Click here to Skip to main content
15,916,463 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using System.Net;
using System.IO;

namespace FCMSQL
{
    public class BaseFunctionClass
    {

         public BaseFunctionClass()
        { 
                   
        }
        

        #region "Welcome Function"
        /// <summary>
        /// This function will be called from the SQL Stored Procedure.
        /// </summary>
        /// <param name=""strName"">Name</param>
        /// <returns>Welcome Message</returns>
        [SqlProcedure]
        public static void GetMessage(SqlString strName, out SqlString strMessge)
        {

            string serverKey = "AAAAYMU8LNo:APA91bHkuINssRFTKcW8Cc1r9i3ZsERgLtS8DQqnnZzXkLZ3Xwj2nL9LujhlecCyzl5a4vc_K7859DqLTv8Q0bUqfCYi4M7yifZPUgaE9ck4cLt2N73oWbfNr4G1psffc828rIYzVa4U";

          
                var result = "-1";
                var webAddr = "https://fcm.googleapis.com/fcm/send";

                var regID = "dOw3Z_v6Gsg:APA91bGdmf_mkCmQsKWQH0vNCpfifawOeXOzKBqMxcFxhy4A88bo56qKE_-vGbTE_lAkcrWU1_5svhR3l6q6PqU0Sr6agJq0SVhmMxHe9MPPEpahGxHVeNdjX_xhma3VqQVZ6o2HqEAN";

                var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Headers.Add("Authorization:key=" + serverKey);
                httpWebRequest.Method = "POST";

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"to\": \"" + regID + "\",\"notification\": {\"title\": \"New deal\",\"body\": \"welcome \"},\"priority\":10}";
                    //registration_ids, array of strings -  to, single recipient
                    streamWriter.Write(json);
                    streamWriter.Flush();
                }

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    result = streamReader.ReadToEnd();
                }



          strMessge = "Welcome," + strName + ", " + "your code is gettingexecuted under CLR !";
        }

        #endregion



    }
}


What I have tried:

How to convert this piece of code into C# file or just tell how to run this code in C#.
Posted
Updated 29-Jun-18 6:42am
Comments
GKP1992 29-Jun-18 4:02am    
What is the error you get when trying to run it? By the looks of it, this code is already in C# so you don't need to convert it to C#.
Richard MacCutchan 29-Jun-18 4:55am    
It is already C#, so you just need to build it with Visual Studio and then execute it.

When you find random code samples on the internet, the first thing to do is try and understand it. You can then think about including it in your code base.

If you can;t understand it, then you probably shouldn't use it: it could do anything.

And we have no idea what that code was written to do, or what you think it might do, or what it actually does in the context of your application.

So go back to where you got it, and ask there - they should at least know what it is meant to do, which is a lot more than us...
 
Share this answer
 
C#
string serverKey = "AAAAYMU8LNo:APA91bHkuINssRFTKcW8Cc1r9i3ZsERgLtS8DQqnnZzXkLZ3Xwj2nL9LujhlecCyzl5a4vc_K7859DqLTv8Q0bUqfCYi4M7yifZPUgaE9ck4cLt2N73oWbfNr4G1psffc828rIYzVa4U";
...
var regID = "dOw3Z_v6Gsg:APA91bGdmf_mkCmQsKWQH0vNCpfifawOeXOzKBqMxcFxhy4A88bo56qKE_-vGbTE_lAkcrWU1_5svhR3l6q6PqU0Sr6agJq0SVhmMxHe9MPPEpahGxHVeNdjX_xhma3VqQVZ6o2HqEAN";

Publishing this in a public forum is a major security problem because anyone can use and abuse that account.
I recommend to revoke those keys and generate new ones as soon as possible.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900