コード例 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Page);

            //update local tag cache
            m_sBaseDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            this.UpdateTagCache();

            m_pTags    = FindViewById <EditText>(Resource.Id.txtTags);
            m_pSources = FindViewById <EditText>(Resource.Id.txtSource);

            EditText pSnippetContent = FindViewById <EditText>(Resource.Id.txtSnippetContent);
            EditText pSourceData     = FindViewById <EditText>(Resource.Id.txtSourceData);

            Button pTagsButton = FindViewById <Button>(Resource.Id.btnTagsList);

            pTagsButton.Click += delegate
            {
                this.DisplayList("tags");
            };
            Button pSourceButton = FindViewById <Button>(Resource.Id.btnSourceList);

            pSourceButton.Click += delegate
            {
                this.DisplayList("sources");
            };

            Button pSubmitButton = FindViewById <Button>(Resource.Id.btnSubmit);

            pSubmitButton.Click += delegate
            {
                string sContent = pSnippetContent.Text;
                string sTags    = m_pTags.Text + ",source:" + m_pSources.Text;

                // add meta tags
                //sContent = "<meta name='sourceTag' content='" + lblSourceName.Content + "'><meta name='source' content='" + txtSourceText.Text + "'>" + sContent;
                sContent = "<meta name='sourceTag' content='" + m_pSources.Text + "'><meta name='source' content='" + pSourceData.Text + "'>" + sContent;

                // make the xml request body
                string sBody = "<params>";
                sBody += "<param name='sTagList'>" + sTags + "</param><param name='sSnippet'>" + Master.EncodeXML(sContent) + "</param>";
                if (m_bEditing)
                {
                    sBody += "<param name='sFileName'>" + m_sEditingSnippet + "</param>";
                }
                sBody += "</params>";

                string sResponse = "";
                if (m_bEditing)
                {
                    sResponse = WebCommunications.SendPostRequest("http://dwlapi.azurewebsites.net/api/reflection/KnowledgeBaseServer/KnowledgeBaseServer/KnowledgeServer/EditSnippet", sBody, true);
                }
                else
                {
                    sResponse = WebCommunications.SendPostRequest("http://dwlapi.azurewebsites.net/api/reflection/KnowledgeBaseServer/KnowledgeBaseServer/KnowledgeServer/AddSnippet", sBody, true);
                }

                this.Finish();
            };

            Button pDeleteButton = FindViewById <Button>(Resource.Id.btnDelete);

            pDeleteButton.Click += delegate
            {
                if (!m_bEditing)
                {
                    return;
                }

                // thanks to https://forums.xamarin.com/discussion/6096/how-show-confirmation-message-box-in-vs-2012
                var pBuilder = new AlertDialog.Builder(this);
                pBuilder.SetMessage("Are you sure you want to delete this snippet?");
                pBuilder.SetPositiveButton("Yes", (s, e) =>
                {
                    WebCommunications.SendGetRequest("http://dwlapi.azurewebsites.net/api/reflection/KnowledgeBaseServer/KnowledgeBaseServer/KnowledgeServer/DeleteSnippet?sfilename=" + m_sEditingSnippet, true);
                    this.Finish();
                });
                pBuilder.SetNegativeButton("No", (s, e) => { return; });
                pBuilder.Create().Show();
            };

            string sType = this.Intent.GetStringExtra("Type");

            if (sType == "new")
            {
                m_bEditing = false;
            }
            else if (sType == "edit")
            {
                string sSnippetName       = this.Intent.GetStringExtra("SnippetName");
                string sSnippetSourceName = this.Intent.GetStringExtra("SourceName");
                string sSnippetSourceText = this.Intent.GetStringExtra("SourceText");
                string sSnippetTags       = this.Intent.GetStringExtra("SnippetTags");

                m_bEditing        = true;
                m_sEditingSnippet = sSnippetName;

                // get the actual snippet content from the server
                string sSnippetContent = WebCommunications.SendGetRequest("http://dwlapi.azurewebsites.net/api/reflection/KnowledgeBaseServer/KnowledgeBaseServer/KnowledgeServer/GetSnippet?sfilename=" + sSnippetName, true);
                sSnippetContent = Master.CleanResponseForEditor(sSnippetContent);

                // remove the meta tags (since they are merely added back in on submit)
                Regex pRegex = new Regex(s_sMetaPattern);
                sSnippetContent = pRegex.Replace(sSnippetContent, "");

                // fill fields
                pSnippetContent.Text = sSnippetContent;
                pSourceData.Text     = sSnippetSourceText;
                m_pTags.Text         = sSnippetTags;
                m_pSources.Text      = sSnippetSourceName;

                this.Title = "Edit Snippet";
            }
        }
コード例 #2
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (resultCode == Result.Ok)
            {
                // TODO: HANDLE EXTRA HERE
                string sType = data.GetStringExtra("Type");

                XElement pResponse         = null;
                bool     bRestartRequested = false;


                if (sType == "initial")
                {
                    string sRule = data.GetStringExtra("Rule");
                    string sInitialCorrectKoan   = data.GetStringExtra("CorrectKoan");
                    string sInitialIncorrectKoan = data.GetStringExtra("IncorrectKoan");

                    string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='sRule'>" + sRule + "</param><param name='sBuddhaNatureKoan'>" + sInitialCorrectKoan + "</param><param name='sNonBuddhaNatureKoan'>" + sInitialIncorrectKoan + "</param>");
                    string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitInitialKoans", sBody, true);
                    if (Master.CleanResponse(sResponse) != "")
                    {
                        pResponse = Master.ReadResponse(sResponse);
                    }
                }
                else if (sType == "build")
                {
                    string sKoan  = data.GetStringExtra("Koan");
                    bool   bMondo = data.GetBooleanExtra("Mondo", false);

                    string sBody = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='sKoan'>" + sKoan + "</param>");

                    string sResponse = "";
                    if (!bMondo)
                    {
                        sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitKoan", sBody, true);
                    }
                    else
                    {
                        sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitMondo", sBody, true);
                    }
                    if (Master.CleanResponse(sResponse) != "")
                    {
                        pResponse = Master.ReadResponse(sResponse);
                    }
                    bRestartRequested = true;
                }
                else if (sType == "analysis")
                {
                    bool bHasBuddhaNature = data.GetBooleanExtra("HasBuddhaNature", false);

                    string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='bHasBuddhaNature'>" + bHasBuddhaNature + "</param>");
                    string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitPendingKoanAnalysis", sBody, true);
                    if (Master.CleanResponse(sResponse) != "")
                    {
                        pResponse = Master.ReadResponse(sResponse);
                    }
                }
                else if (sType == "predict")
                {
                    bool bPrediction = data.GetBooleanExtra("Prediction", false);

                    string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='bPrediction'>" + bPrediction + "</param>");
                    string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitMondoPrediction", sBody, true);
                    if (Master.CleanResponse(sResponse) != "")
                    {
                        pResponse = Master.ReadResponse(sResponse);
                    }
                    bRestartRequested = true;
                }
                else if (sType == "guess")
                {
                    string sGuess = data.GetStringExtra("Guess");

                    string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='sGuess'>" + Master.EncodeXML(sGuess) + "</param>");
                    string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitGuess", sBody, true);
                    if (Master.CleanResponse(sResponse) != "")
                    {
                        pResponse = Master.ReadResponse(sResponse);
                    }
                    bRestartRequested = true;
                }
                else if (sType == "disprove")
                {
                    bool bSuccessfullyDisproved = data.GetBooleanExtra("Disprove", false);
                    if (!bSuccessfullyDisproved)
                    {
                        string sAltResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "GrantEnlightenment", Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID)), true);
                        if (Master.CleanResponse(sAltResponse) != "")
                        {
                            pResponse = Master.ReadResponse(sAltResponse);
                        }
                    }
                    else
                    {
                        string sKoan            = data.GetStringExtra("Koan");
                        bool   bHasBuddhaNature = data.GetBooleanExtra("HasBuddhaNature", false);

                        string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='sKoan'>" + sKoan + "</param><param name='bHasBuddhaNature'>" + bHasBuddhaNature + "</param>");
                        string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "DisproveGuess", sBody, true);
                        if (Master.CleanResponse(sResponse) != "")
                        {
                            pResponse = Master.ReadResponse(sResponse);
                        }
                    }
                }

                if (pResponse != null)
                {
                    var pBuilder = new AlertDialog.Builder(this);
                    pBuilder.SetMessage(pResponse.Element("Text").Value);
                    pBuilder.SetPositiveButton("Ok", (e, s) => { return; });
                    pBuilder.Show();
                }
                else if (bRestartRequested)
                {
                    this.ForceRestart();
                }
                else
                {
                    this.GetUserBoard();
                }
            }
        }