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


C# Response.Append方法代码示例

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


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

示例1: Delete

        public override Response Delete(string objectType, IList<string> identifiers)
        {
            Response response = new Response();

            if (identifiers == null || identifiers.Count == 0)
            {
                Status status = new Status();
                status.Level = StatusLevel.Warning;
                status.Messages.Add("Nothing to delete.");
                response.Append(status);
                return response;
            }

            try
            {
                foreach (string identifier in identifiers)
                {
                    Status status = new Status();
                    status.Identifier = identifier;
                    string message = String.Empty;
                    try
                    {
                        if (String.IsNullOrWhiteSpace(identifier))
                            throw new ApplicationException("Identifier can not be blank or null.");

                        string url = GenerateUrl(objectType, identifier);
                        _webClient.MakeDeleteRequest(url);

                        message = String.Format("DataObject [{0}] deleted successfully.", identifier);
                        status.Messages.Add(message);
                        response.Append(status);
                    }
                    catch
                    {
                        message = String.Format("Error while deleting dataObject [{0}].", identifier);
                        status.Messages.Add(message);
                        response.Append(status);
                    }
                }

            }
            catch (Exception ex)
            {
                _logger.ErrorFormat("Error while deleting a list of data objects of type [{0}]: {1}", objectType, ex);
                throw new Exception("Error while deleting a list of data objects of type [" + objectType + "].", ex);
            }

            return response;
        }
开发者ID:iringtools,项目名称:rest_dl,代码行数:49,代码来源:RestDataLayer2.cs

示例2: Post

        public override Response Post(IList<IDataObject> dataObjects)
        {
            Response response = new Response();
            string objectType = String.Empty;
            bool isNew = false;
            string identifier = String.Empty;

            objectType = ((GenericDataObject)dataObjects.FirstOrDefault()).ObjectType;
            DataObject objDef = _dataDictionary.dataObjects.Find(p => p.objectName.ToUpper() == objectType.ToUpper());

            if (dataObjects == null || dataObjects.Count == 0)
            {
                Status status = new Status();
                status.Level = StatusLevel.Warning;
                status.Messages.Add("Data object list provided is empty.");
                response.Append(status);
                return response;
            }

            try
            {

                foreach (IDataObject dataObject in dataObjects)
                {
                    identifier = String.Empty;
                    Status status = new Status();
                    string message = String.Empty;

                    try
                    {
                        String objectString = FormJsonObjectString(dataObject);
                        foreach (KeyProperty dataProperty in objDef.keyProperties)
                        {
                            string value = Convert.ToString(dataObject.GetPropertyValue(dataProperty.keyPropertyName));
                            if (String.IsNullOrEmpty(value))
                                isNew = true;
                            else
                                identifier = value;
                            break;
                        }
                        if (!String.IsNullOrEmpty(identifier))
                        {
                            int count = Get(objectType, new List<string>() { identifier }).Count;
                            if (count > 0)
                                isNew = false;
                            else
                                isNew = true;
                        }

                        string url = GenerateUrl(objectType);
                        if (isNew) ///Post data
                        {
                            _webClient.MakePostRequest(url, objectString);
                        }
                        else ///put data
                        {
                            _webClient.MakePutRequest(url, objectString);
                        }

                        message = String.Format("Data object [{0}] posted successfully.", identifier);
                        status.Messages.Add(message);
                        response.Append(status);

                    }
                    catch (Exception ex)
                    {
                        message = String.Format("Error while posting data object [{0}].", identifier);
                        status.Messages.Add(message);
                        response.Append(status);
                    }

                }

            }
            catch (Exception ex)
            {
                _logger.ErrorFormat("Error while processing a list of data objects of type [{0}]: {1}", objectType, ex);
                throw new Exception("Error while processing a list of data objects of type [" + objectType + "].", ex);
            }

            return response;
        }
开发者ID:iringtools,项目名称:rest_dl,代码行数:82,代码来源:RestDataLayer2.cs


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