コード例 #1
0
 public Thief(string name)
 {
     stat_strength     = RND.Next(2, 9);
     stat_intelligence = RND.Next(2, 9);
     stat_agility      = RND.Next(8, 17);
     myname            = name;
 }
コード例 #2
0
        public static string Generate(int length)
        {
            string token = "";

            while (token.Length < length)
            {
                int bottleFlip = RND.Next(0, 3);
                // 0 = number (0-9)
                // 1 = upper (A-Z)
                // 2 = lower (a-z)
                if (bottleFlip == 0)
                {
                    token += RND.Next(0, 10).ToString();
                }
                else if (bottleFlip == 1)
                {
                    int  id  = RND.Next(65, 91);
                    char chr = Convert.ToChar(id);
                    token += chr.ToString();
                }
                else
                {
                    int  id  = RND.Next(97, 123);
                    char chr = Convert.ToChar(id);
                    token += chr.ToString();
                }
            }
            return(token);
        }
コード例 #3
0
        public void FindPrimeNumber()
        {
            int n = (RND.Next() % 16) + 1000;

            int count = 0;
            int a     = 2;

            while (count < n)
            {
                long b     = 2;
                int  prime = 1; // to check if found a prime
                while (b * b <= a)
                {
                    if (a % b == 0)
                    {
                        prime = 0;
                        break;
                    }

                    b++;
                }

                if (prime > 0)
                {
                    count++;
                }
                a++;
            }

            result = --a * 333; //the result can be processed
        }
コード例 #4
0
        IEnumerator <TaskContract> FindPrimeNumber()
        {
            while (true)
            {
                int n = (RND.Next() % 16) + 1000;

                int count = 0;
                int a     = 2;
                while (count < n)
                {
                    long b     = 2;
                    int  prime = 1; // to check if found a prime
                    while (b * b <= a)
                    {
                        if (a % b == 0)
                        {
                            prime = 0;
                            break;
                        }

                        b++;
                    }

                    if (prime > 0)
                    {
                        count++;
                    }
                    a++;
                }

                yield return(--a * 333); //the result can be processed
            }
        }
コード例 #5
0
 public Instructions()
 {
     instructions["ST"]   = new ST();
     instructions["LD"]   = new LD();
     instructions["ADD"]  = new ADD();
     instructions["SUB"]  = new SUB();
     instructions["JMP"]  = new JMP();
     instructions["JN"]   = new JN();
     instructions["JP"]   = new JP();
     instructions["JZ"]   = new JZ();
     instructions["JNZ"]  = new JNZ();
     instructions["HALT"] = new HALT();
     //Second architecture functions.
     instructions["LD2"] = new LD2();
     instructions["LD3"] = new LD3();
     instructions["ST2"] = new ST2();
     instructions["ST3"] = new ST3();
     instructions["POS"] = new POS();
     instructions["PXL"] = new PXL();
     instructions["RND"] = new RND();
     instructions["CLR"] = new CLR();
     instructions["COS"] = new COS();
     instructions["SIN"] = new SIN();
     instructions["IN"]  = new IN();
 }
コード例 #6
0
 static void Random()
 {
     Array = new int[60];
     for (int i = 0; i < Array.Length; i++)
     {
         Array[i] = RND.Next(100);
     }
 }
コード例 #7
0
        public Macroblock(World GW)
        {
            this.Size       = ChunkSize;
            this.ShaderProg = GlobalShaderProg;
            this.Atlas      = GlobalAtlas;
            this.GW         = GW;

            Clr = new Vector3((float)RND.Next(0, 100) / 100, (float)RND.Next(0, 100) / 100, (float)RND.Next(0, 100) / 100);

            ChunkMatrix = Matrix4.Identity;
        }
コード例 #8
0
        public override int Execute(Miner entity)
        {
            // try to put miner into drinking state
            int result = RND.Roll(100);

            if (result >= 80)
            {
                entity.StateMachine.State = entity.StateMachine.DrinkFromMagicFlask;
            }
            return(0);
        }
コード例 #9
0
 public override int Execute(Miner entity)
 {
     // every action makes miner thirsty and more exhausted
     entity.Thirst++;
     entity.Fatigue++;
     Console.WriteLine($"{entity.Name}: in vigorous state");
     if (entity.Fatigued() && entity.Thirsty())
     {
         entity.StateMachine.State = entity.StateMachine.Tired;
     }
     return(RND.Roll(100));
 }
コード例 #10
0
        ///// <summary>
        ///// Ręcznie zrobione URLEncode
        ///// </summary>
        ///// <param name="x"></param>
        ///// <returns></returns>
        //internal static string URLEncode2(string x)
        //{
        //    x = x ?? "";
        //    string src1 = new string(URLENCODE_SRC);
        //    StringBuilder sb = new StringBuilder();
        //    foreach (char c in x)
        //    {
        //        int i = src1.IndexOf(c);
        //        if (i < 0)
        //            sb.Append(c);
        //        else
        //            sb.Append(URLENCODE_DST[i]);
        //    }
        //    return sb.ToString();
        //}


        #region Static Methods

        // Protected Methods 

        protected static string RandomStr(int l)
        {
            string result = "";

            while (result.Length < l)
            {
                byte[] rr = new byte[128];
                RND.NextBytes(rr);
                result += Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Replace("=", "").Replace("/", "a").Replace("\\", "a").Replace("+", "");
            }
            return(result.Substring(0, l));
        }
コード例 #11
0
        static void Main(string[] args)
        {
            Miner bob = new Miner()
            {
                Name               = "Bob", Location = LocationType.shack1, Home = LocationType.shack1,
                Capacity           = 10, ComfortLevel = 20,
                TirednessThreshold = 10, ThirstLevel = 12
            };
            Miner jim = new Miner()
            {
                Name               = "Jim", Location = LocationType.shack2, Home = LocationType.shack2,
                Capacity           = 4, ComfortLevel = 25,
                TirednessThreshold = 15, ThirstLevel = 15
            };

            // connect them directly, simplistic solution
            bob.Rival = jim;

            for (int i = 0; i < 200; i++)
            {
                // provoke monster invasion
                if (RND.Roll(100) >= 80)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Invasion is coming.");
                    Console.ResetColor();
                    MessageBroker.Instance.Dispatch(new Telegram
                    {
                        Delay    = 0,
                        Message  = (int)Messages.Invasion,
                        Receiver = bob,
                        Sender   = null
                    });
                    MessageBroker.Instance.Dispatch(new Telegram
                    {
                        Delay    = 0,
                        Message  = (int)Messages.Invasion,
                        Receiver = jim,
                        Sender   = null
                    });
                }
                bob.Update();
                jim.Update();
                MessageBroker.Instance.DispatchDelayedMessages();
                Thread.Sleep(100);
                Console.WriteLine();
            }
            bob.Print();
            Console.WriteLine("---------");
            jim.Print();
        }
コード例 #12
0
        public static T Pick <T>(this IEnumerable <T> list, Random RND = null)
        {
            if (RND == null)
            {
                RND = new Random();
            }
            List <T> L = new List <T>();

            foreach (var item in list)
            {
                L.Add(item);
            }
            return(L[RND.Next(L.Count)]);
        }
コード例 #13
0
 public void Randomize()
 {
     ForEachLayer(
         layer =>
         ForEachNeuron(
             layer,
             neuron =>
     {
         for (var i = 0; i < neuron.Weights.Length; i++)
         {
             neuron.Weights[i] = (float)RND.NextDouble();
         }
     }));
 }
コード例 #14
0
 public override int Execute(Miner entity)
 {
     // every action makes miner double thirsty and more exhausted
     entity.Thirst++;
     entity.Thirst++;
     entity.Fatigue++;
     Console.WriteLine($"{entity.Name}: in tired state");
     if (!entity.Fatigued() || !entity.Thirsty())
     {
         entity.StateMachine.State = entity.StateMachine.Vigorous;
     }
     // can do much less when tired
     return(RND.Roll(70));
 }
コード例 #15
0
public static double[] plain
(Func<vector,double> f, double[] a, double[] b, int npoints, Random RND=null){
	if(RND==null)RND=new Random();
	double volume=1; for(int i=0;i<a.Length;i++) volume*=(b[i]-a[i]);
	var x=new vector(a.Length);
	double average=0,variance=0;
	for(int n=0;n<npoints;n++){
		for(int i=0;i<x.size;i++) x[i]=a[i]+RND.NextDouble()*(b[i]-a[i]);
		double fx=f(x);
		double d1=fx-average;
                average+=d1/(n+1);
		double d2=fx-average;
		variance += d1*d2;
                }
	variance/=(npoints-1);
	return new double[] {average*volume,variance*volume/Sqrt(npoints)};
	}
コード例 #16
0
        public RedEnemy()
        {
            try
            {
                for (int i = 0; i < 8; i++)
                {
                    images.Add(new PictureBox());
                    images[i].Image = new Bitmap($"frame_{i}_delay-0.1s.png");
                }
            }
            catch
            {
                MessageBox.Show("Pictures must be in the same folder as .EXE");
            }

            mainImage.Image    = images[0].Image;
            mainImage.SizeMode = PictureBoxSizeMode.AutoSize;

            hp        = 400;
            yPosition = RND.Next(45, pForm.Height - mainImage.Height - 65);
        }
コード例 #17
0
        public static void Task3()
        {
            DelegateAverage avg = delegate(RND[] dels)
            {
                double result = 0;
                for (int i = 0; i < dels.Length; i++)
                {
                    result += dels[i]();
                }
                return(result);
            };

            RND[]  ddd       = new RND[3];
            Random randomgen = new Random();

            ddd[0] = delegate()
            {
                return(randomgen.NextDouble()); //randov value
            };
            ddd[1] = ddd[0];
            ddd[2] = ddd[1];

            Console.WriteLine(avg(ddd));
        }
コード例 #18
0
 /// <summary>
 /// Method for generating random value of given range
 /// </summary>
 /// <returns>
 /// Random value from given range
 /// </returns>
 public override object GenerateRandom()
 {
     return(RND.Next(RandomMin, RandomMax));
 }
コード例 #19
0
ファイル: mc.cs プロジェクト: AndreasNygaard/PrakProg
    public static double[] stratmc(Func <vector, double> f, double[] a, double[] b, int npoints, bool print_points, Random RND = null)
    {
        if (RND == null)
        {
            RND = new Random(1);
        }
        int dim            = a.Length;
        int min_points     = 8 * dim;
        int min_new_points = 4 * min_points;

        double volume = 1;

        for (int i = 0; i < dim; i++)
        {
            volume *= (b[i] - a[i]);
        }
        var    x  = new vector(dim);
        vector av = new vector(a);
        vector bv = new vector(b);

        if (npoints <= 2 * min_points)//plain MC
        {
            int n1 = npoints / 2;
            int n2 = npoints - n1;
            (double r1, double e1) = plainmc(f, av, bv, n1, print_points, RND);
            (double r2, double e2) = plainmc(f, av, bv, n2, print_points, RND);

            double mcinteg = (n1 * r1 + n2 * r2) / (n1 + n2);
            double mcerror = Abs(r1 - r2) / 4;
            return(new double[] { mcinteg, mcerror });
        }

        int trial_points = (int)Max(min_points, trial_fraction * npoints);
        int new_points   = npoints - trial_points;

        var aL       = new vector(dim);
        var aR       = new vector(dim);
        var vL       = new vector(dim);
        var vR       = new vector(dim);
        var nL       = new int[dim];
        var nR       = new int[dim];
        var sum_f_L  = new vector(dim);
        var sum_f2_L = new vector(dim);
        var sum_f_R  = new vector(dim);
        var sum_f2_R = new vector(dim);

        for (int n = 0; n < trial_points; n++)// trial run
        {
            randomx(x, av, bv, RND, print_points);
            double fx = f(x);
            for (int i = 0; i < dim; i++) // sub-sums
            {
                if (x[i] < (a[i] + b[i]) / 2)
                {
                    nL[i]++;
                    sum_f_L[i]  += fx;
                    sum_f2_L[i] += fx * fx;
                }
                else
                {
                    nR[i]++;
                    sum_f_R[i]  += fx;
                    sum_f2_R[i] += fx * fx;
                }
            }
        }

        double vmax = 0; int i_bisect = RND.Next(0, dim);

        for (int i = 0; i < dim; i++)
        {
            if (nL[i] > 0)
            {
                aL[i] = sum_f_L[i] / nL[i];
                vL[i] = sum_f2_L[i] / nL[i] - Pow(aL[i], 2);
            }
            if (nR[i] > 0)
            {
                aR[i] = sum_f_R[i] / nR[i];
                vR[i] = sum_f2_R[i] / nR[i] - Pow(aR[i], 2);
            }
            double measure = Abs(aL[i] - aR[i]);
            if (measure > vmax)
            {
                vmax     = measure;
                i_bisect = i;
            }
        }

        double weight_L = vL[i_bisect];
        double weight_R = vR[i_bisect];

        if (weight_L == 0 && weight_R == 0)
        {
            weight_L = weight_R = 1;
        }

        int new_points_L = min_points
                           + (int)Round((new_points - 2 * min_points) * weight_L / (weight_L + weight_R));

        int new_points_R = min_points
                           + (int)Round((new_points - 2 * min_points) * weight_R / (weight_L + weight_R));

        if (new_points <= min_new_points)
        {
            new_points_L = new_points / 2;
            new_points_R = new_points - new_points_L;
        }

        var aa = (double[])a.Clone();

        aa[i_bisect] = (a[i_bisect] + b[i_bisect]) / 2;
        var bb = (double[])b.Clone();

        bb[i_bisect] = (a[i_bisect] + b[i_bisect]) / 2;

        double[] result_L = stratmc(f, a, bb, new_points_L, print_points, RND);
        double[] result_R = stratmc(f, aa, b, new_points_R, print_points, RND);

        double new_integ = result_L[0] + result_R[0];
        double new_error = Sqrt(Pow(result_L[1], 2) + Pow(result_R[1], 2));

        double trial_average = (sum_f_L[i_bisect] + sum_f_R[i_bisect]) / trial_points;
        double trial_integ   = trial_average * volume;

        double trial_error = Abs(trial_integ - new_integ) / 4;

        double integ = (trial_integ * trial_points + new_integ * new_points) /
                       (trial_points + new_points);
        double error2 = (Pow(new_error * new_points, 2) + Pow(trial_error * trial_points, 2)) /
                        Pow(new_points + trial_points, 2);
        double error = Sqrt(error2);

        return(new double[] { integ, error });
    }
コード例 #20
0
public static double[] miser
(Func<vector,double> f, double[] a, double[] b, int npoints, Random RND=null)
{
if(RND==null)RND=new Random(1);
int dim=a.Length;
int min_points=8*dim;
int min_new_points=4*min_points;

double volume=1; for(int i=0;i<dim;i++) volume*=(b[i]-a[i]);
var x =new vector(dim);

if(npoints<=2*min_points){//plain MC
/*
	return plain(f,a,b,npoints,RND);
*/
	int n1=npoints/2;
	int n2=npoints-n1;
	double[] r1=plain(f,a,b,n1,RND);
	double[] r2=plain(f,a,b,n2,RND);
	double mcinteg=(n1*r1[0]+n2*r2[0])/(n1+n2);
	double mcerror=Abs(r1[0]-r2[0])/4;
	return new double[] {mcinteg,mcerror};
	}

int trial_points=(int)Max(min_points,trial_fraction*npoints);
int new_points=npoints-trial_points;

var aL=new vector(dim);
var aR=new vector(dim);
var vL=new vector(dim);
var vR=new vector(dim);
var nL=new int[dim];
var nR=new int[dim];
var sum_f_L=new vector(dim);
var sum_f2_L=new vector(dim);
var sum_f_R=new vector(dim);
var sum_f2_R=new vector(dim);

for(int n=0;n<trial_points;n++){// trial run
	randomx(x,a,b,RND);
	double fx=f(x);
	for(int i=0;i<dim;i++){ // sub-sums
		if(x[i]<(a[i]+b[i])/2){nL[i]++;sum_f_L[i]+=fx;sum_f2_L[i]+=fx*fx;}
		else                  {nR[i]++;sum_f_R[i]+=fx;sum_f2_R[i]+=fx*fx;}
		}
	}

double vmax=0;int i_bisect=RND.Next(0,dim);
for(int i=0;i<dim;i++){
	if(nL[i]>0){
		aL[i]=sum_f_L[i]/nL[i];
		vL[i]=sum_f2_L[i]/nL[i]-Pow(aL[i],2);
		}
	if(nR[i]>0){
		aR[i]=sum_f_R[i]/nR[i];
		vR[i]=sum_f2_R[i]/nR[i]-Pow(aR[i],2);
		}
	double measure=Abs(aL[i]-aR[i]);
	//double measure=vL[i]+vR[i];
	//double measure=Max(vL[i],vR[i]);
	if(measure>vmax){vmax=measure;i_bisect=i;}
	}

double weight_L=vL[i_bisect];
double weight_R=vR[i_bisect];
if(weight_L==0 && weight_R==0)weight_L=weight_R=1;

int new_points_L=min_points
+(int)Round((new_points-2*min_points)*weight_L/(weight_L+weight_R));

int new_points_R=min_points
+(int)Round((new_points-2*min_points)*weight_R/(weight_L+weight_R));

if(new_points<=min_new_points){
	new_points_L=new_points/2;
	new_points_R=new_points-new_points_L;
	}

var aa = (double[])a.Clone();aa[i_bisect]=(a[i_bisect]+b[i_bisect])/2;
var bb = (double[])b.Clone();bb[i_bisect]=(a[i_bisect]+b[i_bisect])/2;

double[] result_L = miser(f,a,bb,new_points_L,RND);
double[] result_R = miser(f,aa,b,new_points_R,RND);

double new_integ=result_L[0]+result_R[0];
double new_error=Sqrt(Pow(result_L[1],2)+Pow(result_R[1],2));

double trial_average=(sum_f_L[i_bisect]+sum_f_R[i_bisect])/trial_points;
double trial_integ=trial_average*volume;

/*
double trial_variance=(sum_f2_L[i_bisect]+sum_f2_R[i_bisect])/trial_points
	-trial_average*trial_average;
double trial_error=trial_variance*volume/Sqrt(trial_points);
*/
double trial_error=Abs(trial_integ-new_integ)/4;

double integ=(trial_integ*trial_points+new_integ*new_points)/
	(trial_points+new_points);
double error2=(Pow(new_error*new_points,2)+Pow(trial_error*trial_points,2))/
	Pow(new_points+trial_points,2);
double error=Sqrt(error2);

//return new double[] {integ,Abs(trial_integ-new_integ)};
return new double[] {integ,error};
//return new double[] {integ,new_error};
//return new double[] {new_integ,new_error};

}//miser
コード例 #21
0
 private bool _generateRandomBool()
 {
     return(RND.Next(0, 1) == 1);
 }
コード例 #22
0
 /// <summary>
 /// Method for generating random value of given range
 /// </summary>
 /// <returns>
 /// Random value from given range
 /// </returns>
 public override object GenerateRandom()
 {
     return(Convert.ToUInt32(RND.Next(Convert.ToInt32(RandomMin), Convert.ToInt32(RandomMax))));
 }
コード例 #23
0
 public int GetRnd(RND rnd, int min, int max)
 {
     return(rnd.Value.Next(min, max));
 }
コード例 #24
0
 static public int Rnd(int _min, int _max)
 {
     return(RND.Next(_min, _max));
 }
コード例 #25
0
ファイル: RandomRoller.cs プロジェクト: bogdaniolu97/public
 public int GenerateDie() => RND.Next(1, Constants.DIE_MAX + 1);
コード例 #26
0
 /// <summary>
 /// Method for generating random value of given range
 /// </summary>
 /// <returns>
 /// Random value from given range
 /// </returns>
 public override object GenerateRandom()
 {
     return(RandomMin + Convert.ToSingle(RND.NextDouble()) * (RandomMax - RandomMin));
 }
コード例 #27
0
        // читает вопрос из файла теста
        private Boolean getQw()
        {
            countAns = 0;

            // считываем тэг <q>
            xmlReader.Read();

            if (xmlReader.Name == "q")
            {
                // здесь прочитан тэг <q>,
                // атрибут text которого содержит вопрос, а
                // атрибут src - имя файла иллюстрации.
                //  id = Convert.ToInt32(xmlReader.GetAttribute("id"));
                // извлекаем значение атрибутов:
                qwet = xmlReader.GetAttribute("text");
                pic  = xmlReader.GetAttribute("src");
                if (!pic.Equals(string.Empty))
                {
                    pic = fpath + pic;
                }

                // входим внутрь узла
                xmlReader.Read();
                int i = 0;

                // считываем данные узла вопроса <q>
                while (xmlReader.Name != "q")
                {
                    xmlReader.Read();

                    // варианты ответа
                    if (xmlReader.Name == "a")
                    {
                        // запоминаем правильный ответ
                        if (xmlReader.GetAttribute("right") == "yes")
                        {
                            ro    = i.ToString();//запоминаем номер ответа и переводим его в строку
                            right = i;
                            // MessageBox.Show(ro);
                        }

                        // считываем вариант ответа
                        xmlReader.Read();
                        if (!(String.IsNullOrEmpty(ro))) //если ответ правильный считан
                        {
                            sright = xmlReader.Value;    //запонминаем правильный ответ
                            // MessageBox.Show(sright);
                        }
                        ro = "";
                        answ.Add(xmlReader.Value);

                        // выходим из узла <a>
                        xmlReader.Read();
                        countAns++;
                        i++;
                    }
                    for (int k = 0; k < answ.Count; k++)
                    {
                        string tmp = answ[0];
                        answ.RemoveAt(0);
                        answ.Insert(RND.Next(answ.Count), tmp);
                    }
                    q = new test(qwet, answ);
                    //qwetions.Add(q);
                }

                // выходим из узла вопроса <q>
                xmlReader.Read();

                return(true);
            }
            // если считанный тэг не является
            // тэгом вопроса <q>
            else
            {
                return(false);
            }
        }
コード例 #28
0
 public void GenerateRONumber(  )
 {
     RONumber = RND.Next(100000, 999999);
 }
コード例 #29
0
ファイル: IPNController.cs プロジェクト: gronk555/TutorWeb
        /// <summary>
        /// Request contains IPN from Paypal. Each cart item can have its own quantity of instances. For each instance we generate an activation code.
        /// Increment SoldNumber for module. Send email with activation codes to user.
        /// User goes to market page on the mobile app, no need to select a module, he just enters the code,
        /// the app sends request (code+deviceID) to webapp, that finds Device2Module record with the code, checks it is not used for another deviceID already
        /// and updates the record {moduleID,deviceID,code,activationDate}, sends back response stream with module data. See ModuleController.Download()
        /// </summary>
        private void SendProductCodes()
        {
            try
            {
                Utils.Log(ConfigurationManager.AppSettings["EmailBody"]);                       //TODO: remove in production
                Utils.Log(ConfigurationManager.AppSettings["EmailFooter"]);
                TEST();

                string        mName = HttpUtility.UrlDecode(Request["item_name" + 1]);                  //TODO: comment out these 4 lines for production. In debug msvsmon crashes when EF is called, unless these lines are here.
                List <Module> ml    = db.Modules.ToList();
                var           mm    = ml.FirstOrDefault(o => o.Name == mName);
                Utils.Log(mm.Name);

                int n = 0;
                int.TryParse(Request["num_cart_items"], out n);
                if (n <= 0)
                {
                    throw new Exception("num_cart_items == 0 or not present in IPN");
                }
                string[][] actCode = new string[n][];
                string     body    = ConfigurationManager.AppSettings["EmailBody"];

                for (int x = 0; x < n; x++)
                {
                    //for each instance of bought module create a record with act.code; when user activates it, we'll get his device ID bound to the module instance; only this device will be able to download it.
                    string moduleName = HttpUtility.UrlDecode(Request["item_name" + (x + 1)]);
                    Module m          = db.Modules.FirstOrDefault(o => o.Name == moduleName);
                    if (m == null)
                    {
                        throw new Exception(moduleName + " is not found in DB.");
                    }

                    //if more than one instance of a module is bought, generate act.codes for each instance
                    int quantity = 0;
                    int.TryParse(Request["quantity" + (x + 1)], out quantity);
                    if (quantity <= 0)
                    {
                        throw new Exception("quantity" + (x + 1) + " == 0 or not present in IPN");
                    }
                    actCode[x] = new string[quantity];
                    for (int i = 0; i < quantity; i++)
                    {
                        actCode[x][i] = RND.GetString(8);
                        var d2m = new Device2Module()
                        {
                            ModuleId = m.Id, ActivationCode = actCode[x][i]
                        };
                        db.Device2Module.Add(d2m);
                        body += moduleName + ": " + actCode[x][i] + "\r\n";
                    }
                    m.SoldNumber += quantity;
                    db.SaveChanges();
                }

                string smtpServer = ConfigurationManager.AppSettings["SMTPServer"];
                int    smtpPort   = 0;
                int.TryParse(ConfigurationManager.AppSettings["SMTPPort"], out smtpPort);
                if (smtpPort <= 0)
                {
                    throw new Exception("smtpPort == 0 or not present in web.config");
                }
                string emailSubject       = ConfigurationManager.AppSettings["EmailSubject"];
                string emailFooter        = ConfigurationManager.AppSettings["EmailFooter"];
                string adminEmail         = ConfigurationManager.AppSettings["AdminEmail"];
                string adminEmailPassword = ConfigurationManager.AppSettings["AdminEmailPassword"];

                SmtpClient client = new SmtpClient(smtpServer, smtpPort);                 //587 no ssl
                client.EnableSsl             = true;
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials           = new NetworkCredential(adminEmail, adminEmailPassword);
                client.Send(adminEmail, Request["payer_email"], emailSubject, body + emailFooter);
            }
            catch (Exception ex)
            {
                Utils.Log("IPN.SendProductCodes: " + ex.Message);
            }
        }