Esempio n. 1
0
 public EntityManager(SPDataAccess spDataAccess, KPUser kpUser)
 {
     this.spDataAccess = spDataAccess;
     // diagnostics timer
     this.timer = this.spDataAccess.Timer;
     this.User  = kpUser;
 }
Esempio n. 2
0
        /// <summary>
        /// Save uploaded file to SP document library
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fileStream"></param>
        /// <returns></returns>
        public Message SaveFile(string teamId, Stream fileStream)
        {
            string response = string.Empty;
            int    teamID   = Int16.Parse(teamId);
            string fileGuid = Guid.NewGuid().ToString() + ".docx";
            Dictionary <string, string> responseData = new Dictionary <string, string>();
            var serializer = new DataContractJsonSerializer(typeof(Dictionary <string, string>), new DataContractJsonSerializerSettings()
            {
                UseSimpleDictionaryFormat = true
            });

            try
            {
                KPTimer         timer  = EventLogger.Timer;
                MultipartParser parser = new MultipartParser(fileStream);
                if (parser.Success)
                {
                    // save the file
                    SPDataAccess spDataAccess = new SPDataAccess();
                    spDataAccess.SaveFileToLibrary(teamID, fileGuid, parser.FileContents);
                    // generate response
                    responseData.Add("FileName", fileGuid);
                    responseData.Add("Elapsed", timer.ElapsedMilliseconds().ToString());
                    responseData.Add("Bytes", parser.FileContents.Length.ToString());
                }
                else
                {
                    string errMsg = string.Empty;
                    ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.BadRequest;
                    responseData.Add("Error", "Error parsing filestream");
                    if (parser.FileContents == null)
                    {
                        responseData.Add("FileContents", "no file content sent in request.");
                    }
                    if (parser.ContentType == null)
                    {
                        responseData.Add("ContentType", "no file content-type found in request.");
                    }
                }
            }
            catch (Exception ex)
            {
                ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.BadRequest;
                responseData.Add("Exception", ex.Message);
                if (ex.InnerException != null)
                {
                    responseData.Add("InnerException", ex.InnerException.Message);
                }
            }

            return(this.ctx.CreateJsonResponse <Dictionary <string, string> >(responseData, serializer));
        }
Esempio n. 3
0
 public LookupManager(SPDataAccess spDataAccess)
 {
     this.spDataAccess = spDataAccess;
     this.timer        = spDataAccess.Timer;
 }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ctx"></param>
        /// <param name="items"></param>
        /// <param name="timer"></param>
        /// <returns></returns>
        internal static Message GenerateResponse <T>(WebOperationContext ctx, List <T> items, KPTimer timer)
        {
            Response <T> response;

            response = new Response <T>(items, timer);
            ctx.OutgoingResponse.StatusCode = HttpStatusCode.OK;
            return(ctx.CreateJsonResponse <Response <T> >(response));
        }
Esempio n. 5
0
 public Response(List <T> items, KPTimer timer)
 {
     this.Items   = items;
     this.Count   = items.Count;
     this.Elapsed = timer.ElapsedMilliseconds();
 }
Esempio n. 6
0
 public Response(T item, KPTimer timer)
 {
     this.Item    = item;
     this.Elapsed = timer.ElapsedMilliseconds();
 }
Esempio n. 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="spUtilitites"></param>
 internal EventLogger(SPDataProvider spDataProvider)
 {
     this.spDataProvider = spDataProvider;
     kpTimer             = new KPTimer();
 }
Esempio n. 8
0
 static EventLogger()
 {
     kpTimer = new KPTimer();
 }