Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Centimeter"></param>
 /// <param name="Decimal"></param>
 /// <param name="Comma"></param>
 /// <param name="PostComma"></param>
 /// <param name="Error"></param>
 /// <returns></returns>
 public static string CMtoINCH(string Centimeter, bool Decimal, bool Comma, int PostComma = 0, string Error = Constants.ErrorMessage)
 {
     try
     {
         if (Centimeter.Length <= Constants.VariableLength && Cores.NumberCheck(Centimeter) && !Centimeter.StartsWith("0") && PostComma >= Constants.PostCommaMinimum && PostComma <= Constants.PostCommaMaximum && Cores.UseCheck(Centimeter))
         {
             if (Convert.ToInt64(Centimeter) >= 3)
             {
                 return(Cores.LastCheck2((Convert.ToInt64(Centimeter) * Convert.ToDouble(Values.GetValue("Typography", "CM", "INCH", Error))).ToString(), Decimal, Comma, PostComma, Error));
             }
             else
             {
                 return(Cores.LastCheck2("0", Decimal, Comma, PostComma, Error));
             }
         }
         else
         {
             return(Error);
         }
     }
     catch
     {
         return(Error + Constants.ErrorTitle + "TY-CTI1!)");
     }
 }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Hex"></param>
        /// <param name="Type"></param>
        /// <param name="Error"></param>
        /// <returns></returns>
        public static string HEXtoRGB(string Hex, Enums.ColorType Type = Enums.ColorType.RGB1, string Error = Constants.ErrorMessage)
        {
            try
            {
                if ((Hex.Length == 6 && Cores.UseCheck(Hex)) || (Hex.Length == 7 && Hex.StartsWith("#") && Cores.UseCheck(Hex.Substring(1, Hex.Length - 1))))
                {
                    System.Drawing.Color HexColor;
                    if (Hex.StartsWith("#"))
                    {
                        HexColor = ColorTranslator.FromHtml(Hex);
                    }
                    else
                    {
                        HexColor = ColorTranslator.FromHtml("#" + Hex);
                    }

                    return(Type switch
                    {
                        Enums.ColorType.RGB1 => HexColor.R + ", " + HexColor.G + ", " + HexColor.B,
                        Enums.ColorType.RGB2 => HexColor.R + " " + HexColor.G + " " + HexColor.B,
                        Enums.ColorType.RGB3 => HexColor.R + " - " + HexColor.G + " - " + HexColor.B,
                        Enums.ColorType.RRGGBB1 => "R: " + HexColor.R + ", G: " + HexColor.G + ", B: " + HexColor.B,
                        Enums.ColorType.RRGGBB2 => "R: " + HexColor.R + " G: " + HexColor.G + " B: " + HexColor.B,
                        Enums.ColorType.RRGGBB3 => "R: " + HexColor.R + " - G: " + HexColor.G + " - B: " + HexColor.B,
                        Enums.ColorType.RR => "R: " + HexColor.R,
                        Enums.ColorType.GG => "G: " + HexColor.G,
                        Enums.ColorType.BB => "B: " + HexColor.B,
                        Enums.ColorType.OnlyR => HexColor.R.ToString(),
                        Enums.ColorType.OnlyG => HexColor.G.ToString(),
                        Enums.ColorType.OnlyB => HexColor.B.ToString(),
                        _ => Error,
                    });
                }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Pixel"></param>
 /// <param name="Decimal"></param>
 /// <param name="Comma"></param>
 /// <param name="PostComma"></param>
 /// <param name="Error"></param>
 /// <returns></returns>
 public static string PXtoCM(string Pixel, bool Decimal, bool Comma, int PostComma = 0, string Error = Constants.ErrorMessage)
 {
     try
     {
         if (Pixel.Length <= Constants.VariableLength && Cores.NumberCheck(Pixel) && !Pixel.StartsWith("0") && PostComma >= Constants.PostCommaMinimum && PostComma <= Constants.PostCommaMaximum && Cores.UseCheck(Pixel))
         {
             if (Convert.ToInt64(Pixel) >= 38)
             {
                 return(Cores.LastCheck2((Convert.ToInt64(Pixel) * Convert.ToDouble(Values.GetValue("Typography", "PX", "CM", Error))).ToString(), Decimal, Comma, PostComma, Error));
             }
             else
             {
                 return(Cores.LastCheck2("0", Decimal, Comma, PostComma, Error));
             }
         }
         else
         {
             return(Error);
         }
     }
     catch
     {
         return(Error + Constants.ErrorTitle + "TY-PTC1!)");
     }
 }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Kilometers"></param>
 /// <param name="Decimal"></param>
 /// <param name="Comma"></param>
 /// <param name="PostComma"></param>
 /// <param name="Text"></param>
 /// <param name="Error"></param>
 /// <returns></returns>
 public static string KPHtoMPH(string Kilometers, bool Decimal, bool Comma, int PostComma = 0, bool Text = true, string Error = Constants.ErrorMessage)
 {
     try
     {
         if (Kilometers.Length <= Constants.VariableLength && Cores.NumberCheck(Kilometers) && !Kilometers.StartsWith("0") && PostComma >= Constants.PostCommaMinimum && PostComma <= Constants.PostCommaMaximum && Cores.UseCheck(Kilometers))
         {
             if (Text)
             {
                 return(Cores.LastCheck2((Convert.ToDouble(Kilometers) * Convert.ToDouble(Values.GetValue("Speed", "KPH", "MPH", Error))).ToString(), Decimal, Comma, PostComma, Error) + " MPH");
             }
             else
             {
                 return(Cores.LastCheck2((Convert.ToDouble(Kilometers) * Convert.ToDouble(Values.GetValue("Speed", "KPH", "MPH", Error))).ToString(), Decimal, Comma, PostComma, Error));
             }
         }
         else
         {
             return(Error);
         }
     }
     catch
     {
         return(Error + Constants.ErrorTitle + "SD-KTM1!)");
     }
 }
Пример #5
0
        public void PostInitialise(List <CK2Title> ck2Titles)
        {
            var holder = ck2Titles.Where(t => t.Holder != null).GroupBy(t => t.Holder).OrderBy(group => group.Count()).First().Key;

            //If the province is either: the same relgion as the owner, a primary or accepted culture, or in the dejure territory of the owner then it is a core.
            Cores.AddRange(World.GetCountriesFromCharacter(holder).Where(c => c.Religion == Religion || c.PrimaryCulture == Culture || c.AcceptedCultures.Contains(Culture) || World.Cultures[c.PrimaryCulture].Group.Cultures.Any(cul => cul.Name == Culture) || ck2Titles.Any(t => c.IsDejure(t))));            // c.CountryTag != "KHA"));
            Owner = World.GetIndependentCountryFromCharacter((CK2Character)holder);
            if (Cores.Count == 0)
            {
                Cores.Add(Owner);
            }

            if (ControllerTag == null)
            {
                ControllerTag = Owner.CountryTag;
            }
            //add to owner numholdings
            ck2Titles.ForEach(title =>
            {
                AddToFormable(title);
                CalcCountryEffects(title);
                if (title.Rank == TitleRank.county)
                {
                    title.Province.BaronTitles.ForEach(barony => CalcCountryEffects(barony));
                }
            });
        }
Пример #6
0
        public static void MostrarMensagem(string mensagem, Cores tipoMensagem)
        {
            switch (tipoMensagem)
            {
            case Cores.SUCESSO:
                Console.ForegroundColor = ConsoleColor.Green;
                break;

            case Cores.ERRO:
                Console.ForegroundColor = ConsoleColor.Red;
                break;

            case Cores.ALERTA:
                Console.ForegroundColor = ConsoleColor.Yellow;
                break;

            case Cores.DESTAQUE:
                Console.ForegroundColor = ConsoleColor.Blue;
                break;

            default:
                break;
            }
            System.Console.WriteLine(mensagem);
            Console.ResetColor();

            // System.Console.WriteLine("\nAperte ENTER para prosseguir");
            // Console.ReadLine();
        }
Пример #7
0
        private Eixo VerificaCasaAnterior(Cores Cor, double CasaAnterior)
        {
            Eixo eixo = null;

            switch (Cor)
            {
            case Cores.Azul:
                eixo = posicoes.PosicoesArea.Where(x => x.PosicaoAzul.Equals(CasaAnterior)).FirstOrDefault();
                break;

            case Cores.Verde:
                eixo = posicoes.PosicoesArea.Where(x => x.PosicaoVerde.Equals(CasaAnterior)).FirstOrDefault();
                break;

            case Cores.Amarelo:
                eixo = posicoes.PosicoesArea.Where(x => x.PosicaoAmarelo.Equals(CasaAnterior)).FirstOrDefault();
                break;

            case Cores.Vermelho:
                eixo = posicoes.PosicoesArea.Where(x => x.PosicaoVermelho.Equals(CasaAnterior)).FirstOrDefault();
                break;

            default:
                break;
            }

            return(eixo);
        }
Пример #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Uppercase"></param>
        /// <param name="Error"></param>
        /// <returns></returns>
        public static string TEXTtoSHA512(string Text, bool Uppercase = false, string Error = Constants.ErrorMessage)
        {
            try
            {
                if (Text.Length <= Constants.TextLength && Cores.UseCheck(Text, true))
                {
                    using SHA512 SHA512 = SHA512.Create();
                    byte[]        Result  = SHA512.ComputeHash(ASCIIEncoding.ASCII.GetBytes(Text));
                    StringBuilder Builder = new();
                    for (int i = 0; i < Result.Length; i++)
                    {
                        Builder.Append(Result[i].ToString("x2"));
                    }

                    return(Uppercase == false?Builder.ToString().ToLowerInvariant() : Builder.ToString().ToUpperInvariant());
                }
                else
                {
                    return(Error);
                }
            }
            catch
            {
                return(Error + Constants.ErrorTitle + "CY-TTS4!)");
            }
        }
Пример #9
0
        public bool MatchesDevice(SpecializedDevice device)
        {
            if (SkipUnconditionally)
            {
                return(false);
            }

            if (device == null)
            {
                return(true);
            }

            if (Devices != null)
            {
                if (!Devices.Contains(device.Device.ID))
                {
                    return(false);
                }
            }

            if (Cores != null)
            {
                if (!Cores.Contains(device.Core.ID))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #10
0
        public static void Main()
        {
            //Type enumType = typeof(Cores);
            //Console.WriteLine("{0} info:", enumType);
            //Console.WriteLine ("Names:");
            //foreach (string s in System.Enum.GetNames(enumType))
            //	Console.Write(s + " ");
            //Console.WriteLine ();
            //Console.WriteLine ("Values:");
            //foreach (object o in System.Enum.GetValues(enumType))
            //	Console.Write(o + " ");
            //Console.WriteLine ();
            //// Convert to int
            //Console.WriteLine ("Values converted to int:");
            //foreach (int o in System.Enum.GetValues(enumType))
            //	Console.Write(o + " ");
            //Console.WriteLine ();
            //Console.WriteLine("UnderlyingType: {0}", System.Enum.GetUnderlyingType(enumType));

            Cores c = Cores.Azul;

            Console.WriteLine("c.ToString() = {0}", c.ToString());
            int i = (int)c;

            Console.WriteLine("Enum value converted to int, i = {0}", i);
            Console.WriteLine("(c-1).ToString() = {0}", (c - 1).ToString());
            Console.WriteLine("Cores.Azul - Cores.Verde = {0}", Cores.Azul - Cores.Verde);
            Console.WriteLine("Cores.Azul + 20 = {0}", Cores.Azul + 20);
//			Console.WriteLine("Cores.Azul + 20 is defined? {0}", System.Enum.IsDefined(enumType, Cores.Azul + 20));
//			Console.WriteLine("Cores.Azul + 1 is defined? {0}", System.Enum.IsDefined(enumType, Cores.Azul + 1));
        }
Пример #11
0
        private List <Cores> getCores(String codFamilia)
        {
            try
            {
                ObjectResult <buscaprodutosCores_Result> result = null;

                result = produtos.getProdutosCores(codFamilia);

                if (result != null)
                {
                    foreach (var item in result)
                    {
                        Cores cor = new Cores();
                        cor.ec5cod     = item.ec5cod.Trim();
                        cor.CodFamilia = item.CodFamilia.Trim();
                        listaCores.Add(cor);
                    }
                }
            }
            catch (Exception ex)
            {
                StackTrace      exe = new StackTrace(ex, true);
                CustomException ep  = new CustomException(ex, exe, "");
                ep.Save(AppDomain.CurrentDomain.BaseDirectory + "Log.log");
            }

            return(listaCores);
        }
Пример #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="CHAR"></param>
 /// <param name="Bracket"></param>
 /// <param name="Error"></param>
 /// <returns></returns>
 public static string CHARtoASCII(string CHAR, char Bracket = ',', string Error = Constants.ErrorMessage)
 {
     try
     {
         if (CHAR.Length <= Constants.TextLength && Cores.UseCheck(CHAR, true))
         {
             string Result = string.Empty;
             byte[] LetterByte;
             for (int i = 0; i < CHAR.Length; i++)
             {
                 LetterByte = UTF8Encoding.UTF8.GetBytes(CHAR.Substring(i, 1)); //Encoding.ASCII
                 if (i < CHAR.Length - 1)
                 {
                     Result += LetterByte[0] + Bracket.ToString();
                 }
                 else
                 {
                     Result += LetterByte[0].ToString();
                 }
             }
             return(Result);
         }
         else
         {
             return(Error);
         }
     }
     catch
     {
         return(Error + Constants.ErrorTitle + "US-CTA1!)");
     }
 }
Пример #13
0
        public bool Save(Cores cor)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(cor.Descricao))
                {
                    BStatus.Alert("A descrição da cor é obrigatória");
                    return(false);
                }

                if (db.Find(cor.Id) == null)
                {
                    cor.Id = db.NextId(e => e.Id);
                    db.Save(cor);
                }
                else
                {
                    db.Update(cor);
                }

                db.Commit();
                BStatus.Success("Cor salva com sucesso");
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
 public Triangulo(double ladoA, double ladoB, double ladoC, Cores cor)
     : base(cor)
 {
     LadoA = ladoA;
     LadoB = ladoB;
     LadoC = ladoC;
 }
Пример #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Celsius"></param>
 /// <param name="Decimal"></param>
 /// <param name="Comma"></param>
 /// <param name="PostComma"></param>
 /// <param name="Text"></param>
 /// <param name="Error"></param>
 /// <returns></returns>
 public static string CtoF(string Celsius, bool Decimal, bool Comma, int PostComma = 0, bool Text = true, string Error = Constants.ErrorMessage)
 {
     try
     {
         if (Celsius.Length <= Constants.VariableLength && Cores.NumberCheck(Celsius) && !Celsius.StartsWith("0") && PostComma >= Constants.PostCommaMinimum && PostComma <= Constants.PostCommaMaximum && Cores.UseCheck(Celsius))
         {
             if (Text)
             {
                 return(Cores.LastCheck2((Convert.ToDouble(Celsius) / Convert.ToInt32(Values.GetValue("Temperature", "Celsius", "Divide", Error)) * Convert.ToInt32(Values.GetValue("Temperature", "Celsius", "Multipy", Error)) + Convert.ToInt32(Values.GetValue("Temperature", "Celsius", "Add", Error))).ToString(), Decimal, Comma, PostComma, Error) + " F");
             }
             else
             {
                 return(Cores.LastCheck2((Convert.ToDouble(Celsius) / Convert.ToInt32(Values.GetValue("Temperature", "Celsius", "Divide", Error)) * Convert.ToInt32(Values.GetValue("Temperature", "Celsius", "Multipy", Error)) + Convert.ToInt32(Values.GetValue("Temperature", "Celsius", "Add", Error))).ToString(), Decimal, Comma, PostComma, Error));
             }
         }
         else
         {
             return(Error);
         }
     }
     catch
     {
         return(Error + Constants.ErrorTitle + "TE-CTF1!)");
     }
 }
Пример #16
0
        /// <summary>
        /// 获取或设置缓存对象。
        /// </summary>
        /// <typeparam name="TCache">当前缓存对象类型。</typeparam>
        /// <param name="key">缓存唯一键。</param>
        /// <param name="dependency">缓存依赖项。</param>
        /// <param name="action">获取和配置缓存实例。</param>
        /// <returns>返回当前缓存对象。</returns>
        public virtual async Task <TCache> GetOrCreateAsync <TCache>(object key, IStorageCacheDependency dependency, Func <IStorageContext, Task <TCache> > action)
        {
            var cache = await GetCacheAsync(key, dependency);

            if (cache == null)
            {
                var cacheKey = GetCacheKey(key);
                var context  = new StorageContext(cacheKey);
                var instance = await action(context);

                cache = new StorageCache
                {
                    CacheKey    = cacheKey,
                    Dependency  = dependency?.ToString(),
                    ExpiredDate = context.ExpiredDate
                };
                await _db.CreateAsync(cache);

                await StorageHelper.SaveTextAsync(GetFilePath(cacheKey, true), instance.ToJsonString());

                return(instance);
            }
            var path = GetFilePath(cache.CacheKey);

            if (!File.Exists(path))//缓存文件不存在
            {
                await RemoveAsync(cache.CacheKey);

                return(await GetOrCreateAsync(key, dependency, action));
            }
            return(Cores.FromJsonString <TCache>(await StorageHelper.ReadTextAsync(path)));
        }
Пример #17
0
        public static void SetUnityThreadAffinity(UnityThreads thread, Cores cores)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            // Only support 8 core SoC for now, do nothing otherwise
            if (GetCoresCount() != 8)
            {
                return;
            }

            int mask = 0xFFFF;

            // Assume for now that the first 4 cores are little cores in a 8 core SoC.
            // TODO: Use CPU topology to compute the mask
            if (cores == Cores.Little)
            {
                mask = 0x0F;
            }
            if (cores == Cores.Big)
            {
                mask = 0xF0;
            }

            SetThreadAffinityMaskByName(unityThreadsMap[thread], mask);
#endif
        }
Пример #18
0
        /// <summary>
        /// Retorna a lista de cores em formatos Hexadecimal
        /// </summary>
        /// <Author>Claudinei Nascimento / Vip-Systems Informática & Consultoria Ltda.</Author>
        /// <param name="lista"></param>
        /// <returns></returns>
        public ActionResult CoresRelacionadas(IList <Cores> lista)
        {
            contextoCores = new CoresRepositorio();
            try
            {
                if (lista != null)
                {
                    foreach (var item in lista)
                    {
                        dynamic cor = contextoCores.getCoresSelecionadas(item.ec5cod);

                        foreach (var item2 in cor)
                        {
                            Cores coresRes = new Cores();

                            Color color = UintToColor(item2.bgcolor);
                            var   html  = string.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
                            coresRes.hexadecimal = html;
                            coresRes.ec5cod      = item.ec5cod;

                            coresRes.ec5nom     = item2.descricao.Trim().Trim();
                            coresRes.CodFamilia = item.CodFamilia.Trim();
                            listaCoresPartial.Add(coresRes);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                StackTrace      exe = new StackTrace(ex, true);
                CustomException ep  = new CustomException(ex, exe, "");
                ep.Save(AppDomain.CurrentDomain.BaseDirectory + "Log.log");
            }
            return(PartialView("CoresRelacionadas", listaCoresPartial));
        }
Пример #19
0
        public IActionResult Index(string key)
        {
            int number = 6, fontSize = 16, height = 32;

            if (Request.Query.TryGetValue("n", out var qs) && int.TryParse(qs, out var value))
            {
                number = value;
            }

            if (Request.Query.TryGetValue("s", out qs) && int.TryParse(qs, out value))
            {
                fontSize = value;
            }

            if (Request.Query.TryGetValue("h", out qs) && int.TryParse(qs, out value))
            {
                height = value;
            }

            using var ms = VerifierHelper.Create(out var code, number, fontSize, height);
            Response.Cookies.Append(key, Cores.Hashed(code), new CookieOptions {
                Expires = DateTimeOffset.Now.AddMinutes(3)
            });
            Response.Body.Dispose();
            return(File(ms.ToArray(), @"image/png"));
        }
Пример #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Base64"></param>
 /// <param name="Error"></param>
 /// <returns></returns>
 public static string BASE64toTEXT(string Base64, string Error = Constants.ErrorMessage)
 {
     try
     {
         if (Base64.Length <= Constants.TextLength && Cores.UseCheck(Base64))
         {
             if (Base64.EndsWith("="))
             {
                 try
                 {
                     return(Encoding.UTF8.GetString(Convert.FromBase64String(Base64)));
                 }
                 catch
                 {
                     try
                     {
                         return(Encoding.UTF8.GetString(Convert.FromBase64String(Base64 + "=")));
                     }
                     catch
                     {
                         try
                         {
                             return(Encoding.UTF8.GetString(Convert.FromBase64String(Base64.Remove(Base64.Length - 1))));
                         }
                         catch
                         {
                             return(Encoding.UTF8.GetString(Convert.FromBase64String(Base64.Remove(Base64.Length - 2))));
                         }
                     }
                 }
             }
             else
             {
                 try
                 {
                     return(Encoding.UTF8.GetString(Convert.FromBase64String(Base64)));
                 }
                 catch
                 {
                     try
                     {
                         return(Encoding.UTF8.GetString(Convert.FromBase64String(Base64 + "=")));
                     }
                     catch
                     {
                         return(Encoding.UTF8.GetString(Convert.FromBase64String(Base64 + "==")));
                     }
                 }
             }
         }
         else
         {
             return(Error);
         }
     }
     catch
     {
         return(Error + Constants.ErrorTitle + "CY-BTT1!)");
     }
 }
Пример #21
0
        /// <summary>
        /// 获取或设置缓存对象。
        /// </summary>
        /// <typeparam name="TCache">当前缓存对象类型。</typeparam>
        /// <param name="key">缓存唯一键。</param>
        /// <param name="dependency">缓存依赖项。</param>
        /// <param name="action">获取和配置缓存实例。</param>
        /// <returns>返回当前缓存对象。</returns>
        public TCache GetOrCreate <TCache>(object key, IStorageCacheDependency dependency, Func <IStorageContext, TCache> action)
        {
            var cache = GetCache(key, dependency);

            if (cache == null)
            {
                var cacheKey = GetCacheKey(key);
                var context  = new StorageContext(cacheKey);
                var instance = action(context);
                cache = new StorageCache
                {
                    CacheKey    = cacheKey,
                    Dependency  = dependency?.ToString(),
                    ExpiredDate = context.ExpiredDate
                };
                _db.Create(cache);
                StorageHelper.SaveText(GetFilePath(cacheKey, true), instance.ToJsonString());
                return(instance);
            }
            var path = GetFilePath(cache.CacheKey);

            if (!File.Exists(path))//缓存文件不存在
            {
                Remove(cache.CacheKey);
                return(GetOrCreate(key, dependency, action));
            }
            return(Cores.FromJsonString <TCache>(StorageHelper.ReadText(path)));
        }
Пример #22
0
        public async Task <IHttpActionResult> PutCores(int id, Cores cores)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cores.Id)
            {
                return(BadRequest());
            }

            db.Entry(cores).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CoresExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #23
0
        /// <summary>
        /// <para>prepares devices and compiles kernels in the kernel string</para>
        /// <para>does optionally pipelined kernel execution load balancing between multiple devices</para>
        /// </summary>
        /// <param name="cpuGpu">AcceleratorType.CPU|AcceleratorType.GPU or similar</param>
        /// <param name="kernelString">something like: @"multi-line C# string that has multiple kernel definitions"</param>
        /// <param name="numberofCPUCoresToUseAsDeviceFission">AcceleratorType.CPU uses number of threads for an N-core CPU(between 1 and N-1)(-1 means N-1)</param>
        /// <param name="numberOfGPUsToUse">AcceleratorType.GPU uses number of GPUs equal to this parameter. Between 1 and N(-1 means N)</param>
        /// <param name="stream">devices that share RAM with CPU will not do extra copies. Devices that don't share RAM will directly access RAM and reduce number of copies</param>
        /// <param name="noPipelining">disables extra command queue allocation, can't enable driver-driven pipelining later. Useful for device to device pipelining with many stages.</param>
        public ClNumberCruncher(AcceleratorType cpuGpu, string kernelString,
                                int numberofCPUCoresToUseAsDeviceFission = -1,
                                int numberOfGPUsToUse = -1, bool stream = true, bool noPipelining = false)
        {
            bool defaultQueue = false;

            if (kernelString.Contains("enqueue_kernel("))
            {
                defaultQueue = true;
            }
            repeatCount            = 1;
            numberOfErrorsHappened = 0;
            StringBuilder cpuGpu_ = new StringBuilder("");

            if (((int)cpuGpu & ((int)AcceleratorType.CPU)) > 0)
            {
                cpuGpu_.Append("cpu ");
            }
            if (((int)cpuGpu & ((int)AcceleratorType.GPU)) > 0)
            {
                cpuGpu_.Append("gpu ");
            }
            if (((int)cpuGpu & ((int)AcceleratorType.ACC)) > 0)
            {
                cpuGpu_.Append("acc ");
            }

            List <string> kernelNames_ = new List <string>();

            // extracting patterns kernel _ _ _ void _ _ name _ _ (
            string          kernelVoidRegex = "(kernel[\\s]+void[\\s]+[a-zA-Z\\d_]+[^\\(])";
            Regex           regex           = new Regex(kernelVoidRegex);
            MatchCollection match           = regex.Matches(kernelString);

            for (int i = 0; i < match.Count; i++)
            {
                // extracting name
                Regex           rgx = new Regex("([\\s]+[a-zA-Z\\d_]+)");
                MatchCollection mc  = rgx.Matches(match[i].Value.Trim());
                kernelNames_.Add(mc[mc.Count - 1].Value.Trim());
            }
            if (kernelNames_.Count == 0)
            {
                Console.WriteLine("Error: no kernel definitions are found in string. Kernel string: \n" + kernelString);
                errorNotification = 1;
                return;
            }
            numberCruncher = new Cores(cpuGpu_.ToString(), kernelString, kernelNames_.ToArray(), defaultQueue, 256,
                                       numberOfGPUsToUse, stream, numberofCPUCoresToUseAsDeviceFission, noPipelining);
            if (numberCruncher.errorCode() != 0)
            {
                errorMessage_ = numberCruncher.errorMessage();
                Console.WriteLine(numberCruncher.errorMessage());
                errorNotification = numberCruncher.errorCode();
                numberCruncher.dispose();
                numberOfErrorsHappened++;
                return;
            }
        }
Пример #24
0
        public void GeneralKey()
        {
            var key = Cores.GeneralKey(8);

            Assert.Equal(2, key.Length);
            key = Cores.GeneralKey(128);
            Assert.Equal(32, key.Length);
        }
Пример #25
0
        public void EncryptoOrDecrypt()
        {
            const string text      = "234#$23sdfsdfs$%$d4234234";
            var          encryptor = Cores.Encrypto(text);

            encryptor = Cores.Decrypto(encryptor);
            Assert.Equal(text, encryptor);
        }
Пример #26
0
        protected override void OnLeave(EventArgs e)
        {
            base.OnLeave(e);

            OnTextChanged(e);

            Cores.Out(this, this.Properties.ReadOnly);
        }
Пример #27
0
        internal ClPlatform copy()
        {
            IntPtr     hList = Cores.platformList();
            ClPlatform tmp   = new ClPlatform(hList, platformIndex);

            Cores.deletePlatformList(hList);
            return(tmp);
        }
Пример #28
0
        private string GetCacheFileName(object cacheKey, int minutes)
        {
            var name = Cores.Md5(cacheKey.ToString().Trim());
            var path = $"{name[1]}\\{name[3]}\\{name[12]}\\{name[16]}\\{name[20]}\\{minutes}\\{name}.moz";

            path = Path.Combine(_cacheRootPath, path);
            return(path);
        }
Пример #29
0
        protected override void OnEnter(EventArgs e)
        {
            base.OnEnter(e);

            Cores.In(this, this.Properties.ReadOnly);

            this.Select(this.Text.Length, 0);
        }
Пример #30
0
 /// <summary>
 /// 判断验证码。
 /// </summary>
 /// <param name="key">当前唯一键。</param>
 /// <param name="code">验证码。</param>
 /// <returns>返回判断结果。</returns>
 public bool IsCodeValid(string key, string code)
 {
     if (string.IsNullOrEmpty(code) || !Request.Cookies.TryGetValue(key, out var value))
     {
         return(false);
     }
     code = Cores.Hashed(code);
     return(string.Equals(value, code, StringComparison.OrdinalIgnoreCase));
 }
Пример #31
0
 public Carro(string placa, Modelo modelo, int ano, int km, Cores cor, Direcao dir, bool freio, bool ar, int capacidade)
 {
     Placa = placa;
     ModeloCarro = modelo;
     Ano = ano;
     Quilometragem = km;
     Cor = cor;
     Direcao = dir;
     FreioABS = freio;
     ArCondicionado = ar;
     Capacidade = capacidade;
     Alugado = false;
 }