شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Result

Public general use code classes and xml files that we've compiled and used over the years:

Result support class.

   1:  using System.Collections.Generic;
   2:  using System.Runtime.Serialization;
   3:   
   4:  namespace Ia.Cl.Model
   5:  {
   6:      ////////////////////////////////////////////////////////////////////////////
   7:      /// <summary publish="true">
   8:      /// Result support class.
   9:      /// </summary>
  10:      /// <remarks> 
  11:      /// Copyright © 2001-2016 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  12:      ///
  13:      /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
  14:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  15:      ///
  16:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  17:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  18:      /// 
  19:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  20:      /// 
  21:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  22:      /// </remarks> 
  23:      [DataContract(IsReference = true, Namespace = "kw.com.ia.api", Name = "apiResult")]
  24:      public class Result
  25:      {
  26:          private string title;
  27:          private List<string> successList;
  28:          private List<string> warningList;
  29:          private List<string> errorList;
  30:   
  31:          ////////////////////////////////////////////////////////////////////////////
  32:   
  33:          /// <summary>
  34:          ///
  35:          /// </summary>
  36:          public Result()
  37:          {
  38:              successList = new List<string>();
  39:              warningList = new List<string>();
  40:              errorList = new List<string>();
  41:          }
  42:   
  43:          ////////////////////////////////////////////////////////////////////////////
  44:   
  45:          /// <summary>
  46:          ///
  47:          /// </summary>
  48:          public Result(string title)
  49:          {
  50:              this.title = title;
  51:              successList = new List<string>();
  52:              warningList = new List<string>();
  53:              errorList = new List<string>();
  54:          }
  55:   
  56:          ////////////////////////////////////////////////////////////////////////////
  57:   
  58:          /// <summary>
  59:          ///
  60:          /// </summary>
  61:          [DataMember(Name = "title")]
  62:          public string Title
  63:          {
  64:              get { return title; }
  65:              set { title = value; }
  66:          }
  67:   
  68:          ////////////////////////////////////////////////////////////////////////////
  69:   
  70:          /// <summary>
  71:          ///
  72:          /// </summary>
  73:          [DataMember(Name = "isSuccessful")]
  74:          public bool IsSuccessful
  75:          {
  76:              get
  77:              {
  78:                  return (this.errorList.Count == 0);
  79:              }
  80:   
  81:              // http://stackoverflow.com/questions/2323277/wcf-chokes-on-properties-with-no-set-any-workaround
  82:              private set { }
  83:          }
  84:   
  85:          ////////////////////////////////////////////////////////////////////////////
  86:   
  87:          /// <summary>
  88:          ///
  89:          /// </summary>
  90:          [DataMember(Name = "hasWarning")]
  91:          public bool HasWarning
  92:          {
  93:              get
  94:              {
  95:                  return (this.warningList.Count != 0);
  96:              }
  97:   
  98:              // http://stackoverflow.com/questions/2323277/wcf-chokes-on-properties-with-no-set-any-workaround
  99:              private set { }
 100:          }
 101:   
 102:          ////////////////////////////////////////////////////////////////////////////
 103:   
 104:          /// <summary>
 105:          ///
 106:          /// </summary>
 107:          [DataMember(Name = "hasError")]
 108:          public bool HasError
 109:          {
 110:              get
 111:              {
 112:                  return (this.errorList.Count != 0);
 113:              }
 114:   
 115:              // http://stackoverflow.com/questions/2323277/wcf-chokes-on-properties-with-no-set-any-workaround
 116:              private set { }
 117:          }
 118:   
 119:          ////////////////////////////////////////////////////////////////////////////
 120:   
 121:          /// <summary>
 122:          ///
 123:          /// </summary>
 124:          [DataMember(Name = "message")]
 125:          public string Message
 126:          {
 127:              get
 128:              {
 129:                  string s, success, warning, error;
 130:   
 131:                  s = string.Empty;
 132:   
 133:                  success = Success;
 134:                  warning = Warning;
 135:                  error = Error;
 136:   
 137:                  if (!string.IsNullOrEmpty(Success))
 138:                  {
 139:                      if (!string.IsNullOrEmpty(Warning) && !string.IsNullOrEmpty(Error))
 140:                      {
 141:                          s = "Success: " + Success + ". Warning: " + Warning + ". Error: " + Error + ". ";
 142:                      }
 143:                      else if (!string.IsNullOrEmpty(Warning))
 144:                      {
 145:                          s = "Success: " + Success + ". Warning: " + Warning + ". ";
 146:                      }
 147:                      else if (!string.IsNullOrEmpty(Error))
 148:                      {
 149:                          s = "Success: " + Success + ". Error: " + Error + ". ";
 150:                      }
 151:                      else
 152:                      {
 153:                          s = "Success: " + Success + ". ";
 154:                      }
 155:                  }
 156:                  else
 157:                  {
 158:                      if (!string.IsNullOrEmpty(Warning) && !string.IsNullOrEmpty(Error))
 159:                      {
 160:                          s = "Warning: " + Warning + ". Error: " + Error + ". ";
 161:                      }
 162:                      else if (!string.IsNullOrEmpty(Warning))
 163:                      {
 164:                          s = "Warning: " + Warning + ". ";
 165:                      }
 166:                      else if (!string.IsNullOrEmpty(Error))
 167:                      {
 168:                          s = "Error: " + Error + ". ";
 169:                      }
 170:                      else
 171:                      {
 172:                          s = "";
 173:                      }
 174:                  }
 175:   
 176:                  CleanUp(ref s);
 177:   
 178:                  return s;
 179:              }
 180:   
 181:              // http://stackoverflow.com/questions/2323277/wcf-chokes-on-properties-with-no-set-any-workaround
 182:              private set { }
 183:          }
 184:   
 185:          ////////////////////////////////////////////////////////////////////////////
 186:   
 187:          /// <summary>
 188:          ///
 189:          /// </summary>
 190:          public string Success
 191:          {
 192:              get
 193:              {
 194:                  string s;
 195:   
 196:                  s = string.Empty;
 197:   
 198:                  foreach (string u in successList) s += u + " ";
 199:   
 200:                  if (!string.IsNullOrEmpty(s))
 201:                  {
 202:                      s = s.Remove(s.Length - 1, 1); // remove last ' '
 203:                      //s += ". ";
 204:                  }
 205:   
 206:                  CleanUp(ref s);
 207:   
 208:                  return s;
 209:              }
 210:          }
 211:   
 212:          ////////////////////////////////////////////////////////////////////////////
 213:   
 214:          /// <summary>
 215:          ///
 216:          /// </summary>
 217:          public string Warning
 218:          {
 219:              get
 220:              {
 221:                  string s;
 222:   
 223:                  s = string.Empty;
 224:   
 225:                  foreach (string u in warningList) s += u + " ";
 226:   
 227:                  if (!string.IsNullOrEmpty(s))
 228:                  {
 229:                      s = s.Remove(s.Length - 1, 1); // remove last ' '
 230:                      //s += ". ";
 231:                  }
 232:   
 233:                  CleanUp(ref s);
 234:   
 235:                  return s;
 236:              }
 237:          }
 238:   
 239:          ////////////////////////////////////////////////////////////////////////////
 240:   
 241:          /// <summary>
 242:          ///
 243:          /// </summary>
 244:          public string Error
 245:          {
 246:              get
 247:              {
 248:                  string s;
 249:   
 250:                  s = string.Empty;
 251:   
 252:                  foreach (string u in errorList) s += u + " ";
 253:   
 254:                  if (!string.IsNullOrEmpty(s))
 255:                  {
 256:                      s = s.Remove(s.Length - 1, 1); // remove last ' '
 257:                      //s += ". ";
 258:                  }
 259:   
 260:                  CleanUp(ref s);
 261:   
 262:                  return s;
 263:              }
 264:          }
 265:   
 266:          ////////////////////////////////////////////////////////////////////////////
 267:   
 268:          /// <summary>
 269:          ///
 270:          /// </summary>
 271:          private void CleanUp(ref string line)
 272:          {
 273:              line = line.Replace("..", ".");
 274:              line = line.Replace(". .", ".");
 275:          }
 276:   
 277:          ////////////////////////////////////////////////////////////////////////////
 278:   
 279:          /// <summary>
 280:          ///
 281:          /// </summary>
 282:          public void AddSuccess(string message)
 283:          {
 284:              this.successList.Add(message);
 285:          }
 286:   
 287:          ////////////////////////////////////////////////////////////////////////////
 288:   
 289:          /// <summary>
 290:          ///
 291:          /// </summary>
 292:          public void AddSuccess(string title, string message)
 293:          {
 294:              this.title = title;
 295:              this.successList.Add(message);
 296:          }
 297:   
 298:          ////////////////////////////////////////////////////////////////////////////
 299:   
 300:          /// <summary>
 301:          ///
 302:          /// </summary>
 303:          public void AddWarning(string message)
 304:          {
 305:              this.warningList.Add(message);
 306:          }
 307:   
 308:          ////////////////////////////////////////////////////////////////////////////
 309:   
 310:          /// <summary>
 311:          ///
 312:          /// </summary>
 313:          public void AddWarning(string title, string message)
 314:          {
 315:              this.title = title;
 316:              this.warningList.Add(message);
 317:          }
 318:   
 319:          ////////////////////////////////////////////////////////////////////////////
 320:   
 321:          /// <summary>
 322:          ///
 323:          /// </summary>
 324:          public void AddError(string message)
 325:          {
 326:              this.errorList.Add(message);
 327:          }
 328:   
 329:          ////////////////////////////////////////////////////////////////////////////
 330:   
 331:          /// <summary>
 332:          ///
 333:          /// </summary>
 334:          public void AddError(string title, string message)
 335:          {
 336:              this.title = title;
 337:              this.errorList.Add(message);
 338:          }
 339:   
 340:          ////////////////////////////////////////////////////////////////////////////
 341:   
 342:          /// <summary>
 343:          ///
 344:          /// </summary>
 345:          public void AddResult(Result result)
 346:          {
 347:              this.errorList.AddRange(result.errorList);
 348:              this.warningList.AddRange(result.warningList);
 349:              this.successList.AddRange(result.successList);
 350:          }
 351:   
 352:          ////////////////////////////////////////////////////////////////////////////
 353:   
 354:          /// <summary>
 355:          ///
 356:          /// </summary>
 357:          public void AddResult(string title, Result result)
 358:          {
 359:              this.title = title;
 360:              this.errorList.AddRange(result.errorList);
 361:              this.warningList.AddRange(result.warningList);
 362:              this.successList.AddRange(result.successList);
 363:          }
 364:   
 365:          ////////////////////////////////////////////////////////////////////////////
 366:          ////////////////////////////////////////////////////////////////////////////
 367:      }
 368:   
 369:      ////////////////////////////////////////////////////////////////////////////
 370:      ////////////////////////////////////////////////////////////////////////////
 371:  }