internal void WcfExecute(Stream istream, string contentType)
        {
            string savedFileName, ext, fName;

            ext = context.ExtensionForContentType(contentType);

            savedFileName = FileUtil.getTempFileName(Preferences.getTMP_MEDIA_PATH(), "BLOB", string.IsNullOrEmpty(ext) ? "tmp" : ext);
            GxFile file = new GxFile(Preferences.getTMP_MEDIA_PATH(), savedFileName);

            file.Create(istream);

            JObject obj = new JObject();

            fName = file.GetURI();
            string fileGuid  = GxUploadHelper.GetUploadFileGuid();
            string fileToken = GxUploadHelper.GetUploadFileId(fileGuid);

            obj.Put("object_id", fileToken);
            localHttpContext.Response.AddHeader("GeneXus-Object-Id", fileGuid);
            localHttpContext.Response.ContentType = MediaTypesNames.ApplicationJson;
            HttpHelper.SetResponseStatus(localHttpContext, ((int)HttpStatusCode.Created).ToString(), string.Empty);
            localHttpContext.Response.Write(obj.ToString());

            GxUploadHelper.CacheUploadFile(fileGuid, savedFileName, fName, ext, file, localHttpContext);
        }
Beispiel #2
0
 public string GetExtension()
 {
     if (!string.IsNullOrEmpty(_uploadFileId))
     {
         return(GxUploadHelper.UploadExtension(_uploadFileId));
     }
     else if (this.HasExtension())
     {
         return(System.IO.Path.GetExtension(this.GetAbsoluteName()).Replace(".", ""));
     }
     else
     {
         return(string.Empty);
     }
 }
Beispiel #3
0
 public GxFile(string baseDirectory, string fileName, GxFileType fileType = GxFileType.Public)
     : this(baseDirectory)
 {
     if (GxUploadHelper.IsUpload(fileName))
     {
         _uploadFileId = fileName;
         fileName      = GxUploadHelper.UploadPath(fileName);
     }
     fileName = fileName.Trim();
     if ((GXServices.Instance != null && GXServices.Instance.Get(GXServices.STORAGE_SERVICE) != null) && !Path.IsPathRooted(fileName))
     {
         _file = new GxExternalFileInfo(fileName, ServiceFactory.GetExternalProvider(), fileType);
     }
     else
     {
         _file = new GxFileInfo(fileName, baseDirectory);
     }
 }
Beispiel #4
0
 public string GetName()
 {
     _lastError            = 0;
     _lastErrorDescription = "";
     if (!string.IsNullOrEmpty(_uploadFileId))
     {
         return(GxUploadHelper.UploadName(_uploadFileId));
     }
     if (!validSource())
     {
         return("");
     }
     if (!Exists())
     {
         _lastError = 2;
         return("");
     }
     return(_file.Name);
 }
        public override void webExecute()
        {
            try
            {
                string savedFileName, ext, fName;
                if (context.isMultipartRequest())
                {
                    localHttpContext.Response.ContentType = MediaTypesNames.TextPlain;
                    var r         = new List <UploadFile>();
                    var fileCount = localHttpContext.Request.GetFileCount();
                    for (var i = 0; i < fileCount; i++)
                    {
                        string fileGuid  = GxUploadHelper.GetUploadFileGuid();
                        string fileToken = GxUploadHelper.GetUploadFileId(fileGuid);
                        var    hpf       = localHttpContext.Request.GetFile(i);
                        fName = string.Empty;
                        string[] files = hpf.FileName.Split(new char[] { '\\' });
                        if (files.Length > 0)
                        {
                            fName = files[files.Length - 1];
                        }
                        else
                        {
                            fName = hpf.FileName;
                        }

                        ext           = FileUtil.GetFileType(fName);
                        savedFileName = FileUtil.getTempFileName(Preferences.getTMP_MEDIA_PATH(), FileUtil.GetFileName(fName), string.IsNullOrEmpty(ext) ? "tmp" : ext);
                        GxFile gxFile = new GxFile(Preferences.getTMP_MEDIA_PATH(), savedFileName);

                        gxFile.Create(hpf.InputStream);
                        string uri = gxFile.GetURI();
                        string url = (PathUtil.IsAbsoluteUrl(uri)) ? uri : context.PathToUrl(uri);

                        r.Add(new UploadFile()
                        {
                            name         = fName,
                            size         = gxFile.GetLength(),
                            url          = url,
                            type         = context.GetContentType(ext),
                            extension    = ext,
                            thumbnailUrl = url,
                            path         = fileToken
                        });
                        GxUploadHelper.CacheUploadFile(fileGuid, savedFileName, fName, ext, gxFile, localHttpContext);
                    }
                    UploadFilesResult result = new UploadFilesResult()
                    {
                        files = r
                    };
                    var jsonObj = JSONHelper.Serialize(result);
                    localHttpContext.Response.Write(jsonObj);
                }
                else
                {
                    Stream istream     = localHttpContext.Request.GetInputStream();
                    string contentType = localHttpContext.Request.ContentType;
                    WcfExecute(istream, contentType);
                }
            }
            catch (Exception e)
            {
                SendResponseStatus(500, e.Message);
                HttpHelper.SetResponseStatusAndJsonError(localHttpContext, HttpStatusCode.InternalServerError.ToString(), e.Message);
            }
            finally
            {
                try
                {
                    context.CloseConnections();
                }
                catch
                {
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public virtual Task MethodBodyExecute(object key)
        {
            try
            {
                String innerMethod = EXECUTE_METHOD;
                bool   wrapped     = true;
                Dictionary <string, object> bodyParameters = null;
                if (IsCoreEventReplicator(_procWorker))
                {
                    bodyParameters = ReadBodyParameters();
                    string synchronizer = PreProcessReplicatorParameteres(_procWorker, innerMethod, bodyParameters);
                    if (!IsAuthenticated(synchronizer))
                    {
                        return(Task.CompletedTask);
                    }
                }
                else if (!IsAuthenticated())
                {
                    return(Task.CompletedTask);
                }
                if (Worker.UploadEnabled() && GxUploadHelper.IsUploadURL(_httpContext))
                {
                    GXObjectUploadServices gxobject = new GXObjectUploadServices(_gxContext);
                    gxobject.webExecute();
                    return(Task.CompletedTask);
                }
                if (!ProcessHeaders(_procWorker.GetType().Name))
                {
                    return(Task.CompletedTask);
                }
                _procWorker.IsMain = true;
                if (bodyParameters == null)
                {
                    bodyParameters = ReadBodyParameters();
                }

                if (_procWorker.IsSynchronizer2)
                {
                    innerMethod = SynchronizerMethod();
                    PreProcessSynchronizerParameteres(_procWorker, innerMethod, bodyParameters);
                    wrapped = false;
                }

                if (!String.IsNullOrEmpty(this.ServiceMethod))
                {
                    innerMethod = this.ServiceMethod;
                }
                Dictionary <string, object> outputParameters = ReflectionHelper.CallMethod(_procWorker, innerMethod, bodyParameters, _gxContext);

                wrapped = GetWrappedStatus(_procWorker, wrapped, outputParameters);
                setWorkerStatus(_procWorker);
                _procWorker.cleanup();
                RestProcess(outputParameters);
                return(Serialize(outputParameters, wrapped, _procWorker.IsApiObject));
            }
            catch (Exception e)
            {
                return(WebException(e));
            }
            finally
            {
                Cleanup();
            }
        }
        public override Task Post()
        {
            try
            {
                if (!IsAuthenticated())
                {
                    return(Task.CompletedTask);
                }
                if (Worker.UploadEnabled() && GxUploadHelper.IsUploadURL(_httpContext))
                {
                    GXObjectUploadServices gxobject = new GXObjectUploadServices(_gxContext);
                    gxobject.webExecute();
                    return(Task.CompletedTask);
                }
                bool gxcheck          = IsRestParameter(CHECK_PARAMETER);
                bool gxinsertorupdate = IsRestParameter(INSERT_OR_UPDATE_PARAMETER);

                GxSilentTrnSdt entity           = (GxSilentTrnSdt)Activator.CreateInstance(_worker.GetType(), new Object[] { _gxContext });
                var            entity_interface = MakeRestType(entity);
                entity_interface = ReadRequestBodySDTObj(entity_interface.GetType());

                var worker_interface = MakeRestType(_worker);

                worker_interface.GetType().GetMethod("CopyFrom").Invoke(worker_interface, new object[] { entity_interface });
                if (gxcheck)
                {
                    _worker.Check();
                }
                else
                {
                    if (gxinsertorupdate)
                    {
                        _worker.InsertOrUpdate();
                    }
                    else
                    {
                        _worker.Save();
                    }
                }
                if (_worker.Success())
                {
                    if (!gxcheck)
                    {
                        _worker.trn.context.CommitDataStores();
                        SetStatusCode(HttpStatusCode.Created);
                    }
                    SetMessages(_worker.trn.GetMessages());
                    return(Serialize(MakeRestType(_worker)));
                }
                else
                {
                    Cleanup();
                    return(ErrorCheck(_worker.trn));
                }
            }
            catch (Exception e)
            {
                return(WebException(e));
            }
            finally
            {
                Cleanup();
            }
        }