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


C# Response.Append方法代码示例

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


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

              int id = 0;
              Int32.TryParse(identifier, out id);

              int result = _widgetProvider.DeleteWidgets(id);

              string message = String.Empty;
              if (result == 0)
              {
            message = String.Format(
              "DataObject [{0}] deleted successfully.",
              identifier
            );
              }
              else
              {
            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,项目名称:samples,代码行数:55,代码来源:ObjectDataLayer.cs

示例2: DeleteDataTable

        public override Response DeleteDataTable(string tableName, IList<string> identifiers)
        {
            Response response = new Response();
            response.StatusList = new List<Status>();

            string delimiter = string.Empty;
            IList<string> keyProperties = new List<string>();
            DataObject dataObject = _dictionary.dataObjects.Where<DataObject>(p => p.tableName == tableName).FirstOrDefault();
            keyProperties = (from p in dataObject.keyProperties
                             select p.keyPropertyName).ToList<string>();
            if (keyProperties.Count > 1)
            {
                delimiter = dataObject.keyDelimeter;
            }

            foreach (string identifier in identifiers)
            {
                int i = 0;
                string[] ids = null;
                string tempQry = string.Empty;
                if (keyProperties.Count > 1 && identifier.Contains(delimiter.FirstOrDefault()))
                {
                    ids = identifier.Split(delimiter.FirstOrDefault());

                }
                while (i < keyProperties.Count())
                {
                    if (i != 0)
                    {
                        tempQry += " and ";
                    }
                    IList<DataProperty> property = (from p in dataObject.dataProperties
                                            where p.propertyName == keyProperties[i].ToString()
                                                 select p).ToList();

                    if (keyProperties.Count > 1)
                    {
                        if (property[0].dataType == DataType.Int32)
                        {
                            tempQry = tempQry + keyProperties[i] + " = " + ids[i];
                        }
                        else
                        {
                            tempQry = tempQry + keyProperties[i] + " = '" + ids[i] + "'";
                        }
                    }
                    else
                    {
                        if (property[0].dataType == DataType.Int32)
                        {
                            tempQry = tempQry + keyProperties[i] + " = " + identifier;
                        }
                        else
                        {
                            tempQry = tempQry + keyProperties[i] + " = '" + identifier + "'";
                        }
                    }
                    i++;
                }
                try
                {
                    // Delete From SQL ...
                    ConnectToSqL();
                    string query = "Delete FROM " + tableName + " where " + tempQry;
                    SqlCommand command = new SqlCommand(query, _conn);
                    int iSqlRowCount = command.ExecuteNonQuery();

                    // Delete From Access ...
                    ConnectToAccess();
                    OleDbCommand OleDbcommand = new OleDbCommand(query, _connOledb);
                    int iAccessRowCount = OleDbcommand.ExecuteNonQuery();

                    if (iSqlRowCount > 0 && iAccessRowCount > 0)
                    {
                        Status status = new Status();
                        status.Messages = new Messages();
                        status.Identifier = identifier;
                        status.Messages.Add(string.Format("Record [{0}] have been deleted successfully.", identifier));
                        response.Append(status);
                    }

                }
                catch (Exception ex)
                {
                    logger.Info("Error while deleting the data:   " + ex.Message);
                    throw ex;
                }
                finally
                {
                    disconnectSqL();
                    disconnectAccess();
                }
            }
            return response;
        }
开发者ID:iringtools,项目名称:spr_dl,代码行数:95,代码来源:SPRDataLayer.cs

示例3: SaveDataObjects

        private Response SaveDataObjects(string objectType, IList<IDataObject> dataObjects)
        {
            try
            {
                Response response = new Response();

                // Create data object directory in case it does not exist
                Directory.CreateDirectory(_settings["SP3DFolderPath"]);

                string path = String.Format(
                 "{0}{1}\\{2}.csv",
                   _settings["BaseDirectoryPath"],
                  _settings["SP3DFolderPath"],
                  objectType
                );

                //TODO: Need to update file, not replace it!
                TextWriter writer = new StreamWriter(path);

                foreach (IDataObject dataObject in dataObjects)
                {
                    Status status = new Status();

                    try
                    {
                        string identifier = GetIdentifier(dataObject);
                        status.Identifier = identifier;

                        List<string> csvRow = new List<string>();
                          //FormCSVRow(objectType, dataObject);

                        writer.WriteLine(String.Join(", ", csvRow.ToArray()));
                        status.Messages.Add("Record [" + identifier + "] has been saved successfully.");
                    }
                    catch (Exception ex)
                    {
                        status.Level = StatusLevel.Error;

                        string message = String.Format(
                          "Error while posting dataObject [{0}]. {1}",
                          dataObject.GetPropertyValue("Tag"),
                          ex.ToString()
                        );

                        status.Messages.Add(message);
                    }

                    response.Append(status);
                }

                writer.Close();

                return response;
            }
            catch (Exception ex)
            {
                _logger.Error("Error in LoadDataObjects: " + ex);
                throw new Exception("Error while loading data objects of type [" + objectType + "].", ex);
            }
        }
开发者ID:iringtools,项目名称:sp_3d,代码行数:60,代码来源:SP3DDataLayer.cs

示例4: Post

        public override Response Post(IList<IDataObject> dataObjects)
        {
            Response response = new Response();
              Proxy proxy = null;
              Session session = null;

              try
              {
            if (dataObjects.Count <= 0)
            {
              response.Level = StatusLevel.Error;
              response.Messages.Add("No data objects to update.");
              return response;
            }

            string objType = ((GenericDataObject)dataObjects[0]).ObjectType;
            DataObject objDef = GetObjectDefinition(objType);
            Configuration config = GetConfiguration(objDef);

            Connect(ref proxy, ref session);

            foreach (IDataObject dataObject in dataObjects)
            {
              KeyProperty keyProp = objDef.keyProperties.FirstOrDefault();
              string keyValue = Convert.ToString(dataObject.GetPropertyValue(keyProp.keyPropertyName));

              string revision = string.Empty;
              Map revisionMap = config.Mappings.ToList<Map>().Find(x => x.Destination == (int)Destination.Revision);
              if (revisionMap != null)
              {
            string propertyName = Utilities.ToPropertyName(revisionMap.Column);
            revision = Convert.ToString(dataObject.GetPropertyValue(propertyName));
              }

              EqlClient eql = new EqlClient(session);
              int objectId = eql.GetObjectId(keyValue, revision, config.Template.ObjectType);
              org.iringtools.adapter.datalayer.eb.Template template = config.Template;

              if (objectId == 0)  // does not exist, create
              {
            string templateName = GetTemplateName(template, objDef, dataObject);
            int templateId = eql.GetTemplateId(templateName);

            if (templateId == 0)
            {
              Status status = new Status()
              {
                Identifier = keyValue,
                Level = StatusLevel.Error,
                Messages = new Messages() { string.Format("Template [{0}] does not exist.", templateName) }
              };

              response.StatusList.Add(status);
              response.Level = StatusLevel.Error;

              continue;
            }

            objectId = session.Writer.CreateFromTemplate(templateId, "", "");
              }

              string objectType = Enum.GetName(typeof(ObjectType), template.ObjectType);
              ebProcessor processor = new ebProcessor(session, config.Mappings.ToList<Map>(), _rules);

              if (objectType == ObjectType.Tag.ToString())
              {
            response.Append(processor.ProcessTag(objDef, dataObject, objectId, keyValue));
              }
              else if (objectType == ObjectType.Document.ToString())
              {
            response.Append(processor.ProcessDocument(objDef, dataObject, objectId, keyValue));

            //
            // post content like IW data layer
            //
            if (dataObject.GetType() == typeof(GenericContentObject))
            {
              response.Append(PostContents(new List<IContentObject>{(GenericContentObject) dataObject}, proxy, session));
            }
              }
              else
              {
            Status status = new Status()
            {
              Identifier = keyValue,
              Level = StatusLevel.Error,
              Messages = new Messages() { string.Format("Object type [{0}] not supported.", template.ObjectType) }
            };

            response.StatusList.Add(status);
            response.Level = StatusLevel.Error;
              }
            }
              }
              catch (Exception e)
              {
            _logger.Error("Error posting data objects: " + e);

            response.Level = StatusLevel.Error;
            response.Messages.Add("Error posting data objects: " + e);
//.........这里部分代码省略.........
开发者ID:Vidisha,项目名称:eb,代码行数:101,代码来源:ebDataLayer.cs

示例5: Delete

        public override Response Delete(string objectType, IList<string> identifiers)
        {
            Response response = new Response() { Level = StatusLevel.Success };
              Proxy proxy = null;
              Session session = null;

              try
              {
            DataObject objDef = GetObjectDefinition(objectType);

            if (objDef != null)
            {
              try
              {
            Connect(ref proxy, ref session);

            EqlClient eqlClient = new EqlClient(session);
            Configuration config = GetConfiguration(objDef);
            int objType = (int)config.Template.ObjectType;

            foreach (string identifier in identifiers)
            {
              Status status = new Status()
              {
                Identifier = identifier,
                Level = StatusLevel.Success
              };

              int objId = eqlClient.GetObjectId(identifier, string.Empty, objType);

              if (objId != 0)
              {
                if (objType == (int)ObjectType.Tag)
                {
                  Tag tag = new Tag(session, objId);
                  tag.Delete();
                  status.Messages.Add(string.Format("Tag [{0}] deleted succesfully.", identifier));
                }
                else if (objType == (int)ObjectType.Document)
                {
                  Document doc = new Document(session, objId);
                  doc.Delete();
                  status.Messages.Add(string.Format("Document [{0}] deleted succesfully.", identifier));
                }
                else
                {
                  status.Level = StatusLevel.Error;
                  status.Messages.Add(string.Format("Object type [{0}] not supported.", objType));
                  response.Level = StatusLevel.Error;
                }
              }
              else
              {
                status.Level = StatusLevel.Error;
                status.Messages.Add(string.Format("Object [{0}] not found.", identifier));
                response.Level = StatusLevel.Error;
              }

              response.Append(status);
            }
              }
              finally
              {
            Disconnect(ref proxy, ref session);
              }
            }
            else
            {
              response.Level = StatusLevel.Error;
              response.Messages.Add(string.Format("Object type [{0}] does not exist.", objectType));
            }
              }
              catch (Exception e)
              {
            _logger.Error("Error deleting data object: " + e);

            response.Level = StatusLevel.Error;
            response.Messages.Add(e.Message);
              }

              return response;
        }
开发者ID:Vidisha,项目名称:eb,代码行数:82,代码来源:ebDataLayer.cs

示例6: Post

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

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

              try
              {
            objectType = ((GenericDataObject)dataObjects.FirstOrDefault()).ObjectType;

            switch (objectType.ToUpper())
            {
              case "WIDGET":
            foreach (IDataObject dataObject in dataObjects)
            {
              Status status = new Status();

              Widget widget = FormWidget(dataObject);
              string identifier = widget.Id.ToString();
              status.Identifier = identifier;

              int result = _widgetProvider.UpdateWidgets(new Widgets { widget });

              string message = String.Empty;
              if (result == 0)
              {
                message = String.Format(
                  "Data object [{0}] posted successfully.",
                  identifier
                );
              }
              else
              {
                message = String.Format(
                  "Error while posting data object [{0}].",
                  identifier
                );
              }

              status.Messages.Add(message);

              response.Append(status);
            }
            break;

              default:
            throw new Exception("Invalid object type provided");
            }
              }
              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,项目名称:samples,代码行数:65,代码来源:ObjectDataLayer.cs

示例7: PostDataTable

        protected Response PostDataTable(DataTable dataTable)
        {
            Response response = new Response();

              try
              {
            if (dataTable == null || dataTable.Rows.Count == 0)
            {
              Status status = new Status()
              {
            Level = StatusLevel.Error,
            Messages = new Messages() { "No rows in [" + dataTable.TableName + "] to update." }
              };

              response.StatusList.Add(status);
            }
            else
            {
              string tableName = dataTable.TableName;
              DataObject objDef = _dbDictionary.dataObjects.Find(x => x.tableName.ToLower() == tableName.ToLower());
              Dictionary<string, string> idCmdMap = new Dictionary<string, string>();

              foreach (DataRow row in dataTable.Rows)
              {
            string identifier = FormIdentifier(objDef, row);
            string updateCmd = string.Empty;
            int columnCount = dataTable.Columns.Count;

            if (row.RowState == DataRowState.Added)
            {
              StringBuilder colsBuilder = new StringBuilder();
              StringBuilder valsBuilder = new StringBuilder();

              foreach (DataColumn col in dataTable.Columns)
              {
                if (row[col.ColumnName] != DBNull.Value && row[col.ColumnName] != null)
                {
                  colsBuilder.Append("," + col.ColumnName);

                  if (Utility.IsNumeric(col.DataType))
                  {
                    valsBuilder.Append("," + row[col.ColumnName].ToString());
                  }
                  else
                  {
                    valsBuilder.Append("," + "'" + row[col.ColumnName].ToString() + "'");
                  }
                }
              }

              updateCmd = string.Format(Constants.SQL_INSERT_TEMPLATE, tableName, colsBuilder.Remove(0, 1), valsBuilder.Remove(0, 1));
            }
            else if (row.RowState == DataRowState.Modified) // || row.RowState == DataRowState.Deleted)
            {
              StringBuilder builder = new StringBuilder();
              string whereClause = FormWhereClause(objDef, row);

              foreach (DataColumn col in dataTable.Columns)
              {
                if (row[col.ColumnName] != DBNull.Value && row[col.ColumnName] != null)
                {
                  if (Utility.IsNumeric(col.DataType))
                  {
                    builder.Append("," + col.ColumnName + "=" + row[col.ColumnName].ToString());
                  }
                  else
                  {
                    builder.Append("," + col.ColumnName + "='" + row[col.ColumnName].ToString() + "'");
                  }
                }
              }

              if (row.RowState == DataRowState.Modified)
              {
                updateCmd = string.Format(Constants.SQL_UPDATE_TEMPLATE, tableName, builder.Remove(0, 1), whereClause);
              }
              //else
              //{
              //  updateCmd = string.Format(Constants.SQL_DELETE_TEMPLATE, tableName, whereClause);
              //}
            }

            if (!string.IsNullOrEmpty(identifier) && !string.IsNullOrEmpty(updateCmd))
            {
              idCmdMap[identifier] = updateCmd;
            }
            else
            {
              _logger.Error("[" + identifier + "] not found or unchanged.");
            }
              }

              Response updateResponse = DBManager.Instance.ExecuteUpdate(_stagingConnStr, idCmdMap);
              response.Append(updateResponse);
            }
              }
              catch (Exception ex)
              {
            string error = "Error updating [" + dataTable.TableName + "]: " + ex.Message;

//.........这里部分代码省略.........
开发者ID:iringtools,项目名称:sp_pid,代码行数:101,代码来源:SPPIDDataLayer.cs

示例8: ExecuteUpdate

        public Response ExecuteUpdate(string connStr, Dictionary<string, string> idCmdMap)
        {
            if (idCmdMap == null || idCmdMap.Count == 0)
              {
            string error = "Nothing to update.";
            _logger.Error(error);
            throw new Exception(error);
              }

              Response response = new Response();
              DBType dbType = Utility.GetDBType(connStr);
              DbConnection dbConn = null;

              try
              {
            dbConn = OpenConnection(connStr);

            foreach (var pair in idCmdMap)
            {
              DbCommand dbCmd = null;

              if (dbType == DBType.ORACLE)
              {
            dbCmd = new OracleCommand(pair.Value, (OracleConnection)dbConn);
              }
              else
              {
            dbCmd = new SqlCommand(pair.Value, (SqlConnection)dbConn);
              }

              DbTransaction dbTransaction = dbConn.BeginTransaction();
              dbCmd.Transaction = dbTransaction;
              int affectedRows = dbCmd.ExecuteNonQuery();
              dbTransaction.Commit();

              string message = (affectedRows > 0) ? "[" + pair.Key + "] saved." : "Saving [" + pair.Key + "] failed.";

              Status status = new Status()
              {
            Identifier = pair.Key,
            Level = (affectedRows > 0) ? StatusLevel.Success : StatusLevel.Warning,
            Messages = new Messages { message }
              };

              response.Append(status);
            }

            return response;
              }
              catch (Exception ex)
              {
            string error = "Error excuting update: " + ex.Message;
            _logger.Error(error);
            throw new Exception(error);
              }
              finally
              {
            CloseConnection(dbConn);
              }
        }
开发者ID:iringtools,项目名称:sp_pid,代码行数:60,代码来源:DBManager.cs

示例9: PostDataTables

        public override Response PostDataTables(IList<DataTable> dataTables)
        {
            Response response = new Response();

              foreach (DataTable dataTable in dataTables)
              {
            Response res = PostDataTable(dataTable);
            response.Append(res);
              }

              return response;
        }
开发者ID:iringtools,项目名称:sp_pid,代码行数:12,代码来源:SPPIDDataLayer.cs

示例10: DeleteDataTable

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

              if (identifiers == null || identifiers.Count == 0)
              {
            response.Level = StatusLevel.Error;
            response.Messages = new Messages { "Identifiers not found." };
            return response;
              }

              DataObject objDef = _dbDictionary.dataObjects.Find(x => x.tableName.ToLower() == tableName.ToLower());
              Dictionary<string, string> idCmdMap = new Dictionary<string, string>();

              try
              {
            foreach (string identifier in identifiers)
            {
              string whereClause = FormWhereClause(objDef, identifier);

              if (!string.IsNullOrEmpty(identifier) && !string.IsNullOrEmpty(whereClause))
              {
            idCmdMap[identifier] = "DELETE FROM " + tableName + whereClause;
              }
            }

            Response deleteResponse = DBManager.Instance.ExecuteUpdate(_stagingConnStr, idCmdMap);
            response.Append(deleteResponse);
              }
              catch (Exception ex)
              {
            string error = "Error deleting data rows from [" + tableName + "]: " + ex.Message;
            _logger.Error(error);
            response.Level = StatusLevel.Error;
            response.Messages = new Messages { error };
              }

              return response;
        }
开发者ID:iringtools,项目名称:sp_pid,代码行数:39,代码来源:SPPIDDataLayer.cs

示例11: DeleteDataTable

        public override Response DeleteDataTable(string tableName, IList<string> identifiers)
        {
            Response response = new Response();
            response.StatusList = new List<Status>();

            string delimiter = string.Empty;
            IList<string> keyProperties = new List<string>();
            DataObject dataObject = _dictionary.dataObjects.Where<DataObject>(p => p.tableName == tableName).FirstOrDefault();
            keyProperties = (from p in dataObject.keyProperties
                         select p.keyPropertyName).ToList<string>();
            if (keyProperties.Count > 1)
            {
            delimiter = dataObject.keyDelimeter;
            }

            foreach (string identifier in identifiers)
            {
            int i = 0;
            string[] ids = null;
            string tempQry = string.Empty;
            if (keyProperties.Count > 1 && identifier.Contains(delimiter.FirstOrDefault()))
            {
                ids = identifier.Split(delimiter.FirstOrDefault());

            }
            while (i < keyProperties.Count())
            {
                if (i != 0)
                {
                    tempQry += " and ";
                }

              if (keyProperties.Count > 1)
                  tempQry = tempQry + keyProperties[i] + " = '" + ids[i] +"'";
              else
                  tempQry = tempQry + keyProperties[i] + " = '"+ identifier + "'";
                i++;
            }
            try
            {
                _conn.Open();
                string query = "Delete FROM " + tableName + " where " + tempQry;
                SqlCommand command = new SqlCommand(query, _conn);
                int numberDeleted = command.ExecuteNonQuery();
                if (numberDeleted > 0)
                {
                    Status status = new Status();
                    status.Messages = new Messages();
                    status.Identifier = identifier;
                    status.Messages.Add(string.Format("Record [{0}] have been deleted successfully.", identifier));
                    response.Append(status);
                }

            }
            catch (Exception ex)
            {
                logger.Info("Error while retrieving the data:   " + ex.Message);
                throw ex;
            }
            finally
            {
                if (_conn != null && _conn.State == ConnectionState.Open)
                {
                    _conn.Close();
                }
            }
            }
            return response;
        }
开发者ID:iringtools,项目名称:samples,代码行数:69,代码来源:SQLDataLayer.cs


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