当前位置: 首页>>代码示例>>C#>>正文


C# Service.Delete方法代码示例

本文整理汇总了C#中Google.GData.Client.Service.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# Service.Delete方法的具体用法?C# Service.Delete怎么用?C# Service.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Google.GData.Client.Service的用法示例。


在下文中一共展示了Service.Delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            if (args.Length < 5)
            {
                Console.WriteLine("Not enough parameters. Usage is ExecRequest <service> <cmd> <uri> <username> <password>, where cmd is QUERY, UPDATE, INSERT, DELETE");
                Console.WriteLine("or");
                Console.WriteLine("ExecRequest <service> <cmd> <uri> /a <authsubtoken> - to use a session token");
                Console.WriteLine("or");
                Console.WriteLine("ExecRequest <service> <cmd> <uri> /e <authsubtoken> - to exchance a one time token for a session token");
                return; 
            }

            string s         = args[0];
            string cmd       = args[1];

            string targetUri = args[2];

            string userName = args[3];
            string passWord = args[4];
            

            Service service = new Service(s, ApplicationName);
            
            if (userName.Equals("/a"))
            {
                Console.WriteLine("Using AuthSubToken: " + passWord);
                // password should contain the authsubtoken
                GAuthSubRequestFactory factory = new GAuthSubRequestFactory(s, ApplicationName);
                factory.Token = passWord;
                service.RequestFactory = factory;
            }
            else if (userName.Equals("/e"))
            {
                Console.WriteLine("Using Onetime token: " + passWord);
                passWord = AuthSubUtil.exchangeForSessionToken(passWord, null);
                Console.WriteLine("Exchanged for Session Token: " + passWord);
                // password should contain the authsubtoken
                GAuthSubRequestFactory factory = new GAuthSubRequestFactory(s, ApplicationName);
                factory.Token = passWord;
                service.RequestFactory = factory;
            }
            else 
            {
                Console.WriteLine("Setting user credentials for: " + userName);
                service.setUserCredentials(userName, passWord);
            }

            try
            {
                if (cmd.Equals("QUERY"))
                {
                    Console.WriteLine("Querying: " + targetUri);
                    Stream result = service.Query(new Uri(targetUri));
                    DumpStream(result);
                }
                if (cmd.Equals("DELETE"))
                {
                    service.Delete(new Uri(targetUri));
                    Console.WriteLine("successfully deleted: " + targetUri);
                }
                if (cmd.Equals("POST"))
                {
                    String input = Console.In.ReadToEnd();
                    Console.Write(input);
                    Stream result = service.StringSend(new Uri(targetUri), input, GDataRequestType.Insert);
                    DumpStream(result);
                }
                if (cmd.Equals("UPDATE"))
                {
                    String input = Console.In.ReadToEnd();
                    Console.Write(input);
                    Stream result = service.StringSend(new Uri(targetUri), input, GDataRequestType.Update);
                    DumpStream(result);
                }
            } catch (GDataRequestException e)
            {
                HttpWebResponse response = e.Response as HttpWebResponse;
                Console.WriteLine("Error executing request for Verb: " + cmd + ", Errorcode: " + response.StatusCode);
                Console.WriteLine(response.StatusDescription);
                Console.WriteLine(e.ResponseString);
            }
        }
开发者ID:nagyist,项目名称:GoogleAnalytics-MonoMac-Demo,代码行数:82,代码来源:main.cs


注:本文中的Google.GData.Client.Service.Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。