Пример #1
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            //the actual list of standard items to return
            StandardValuesCollection list = null;

            if (context.Instance is IScreenParameter)
            {
                IScreenParameter parameter = (IScreenParameter)context.Instance;

                if (parameter.InputType == ScreenInputType.Special)
                {
                    List <string> listItems = GetSpecialInputKeys();


                    string[] items = listItems.ToArray <string>();

                    list = new StandardValuesCollection(items);
                }

                if (parameter.InputType == ScreenInputType.User)
                {
                    string[] items = Configuration.GetInstance().App.ProfileProperties.ToArray <string>();

                    list = new StandardValuesCollection(items);
                }
            }

            return(list);
        }
Пример #2
0
        private object GetParameterInputValue(IScreenParameter parameter, object newID)
        {
            object retVal = null;
            App    app    = CodeTorch.Core.Configuration.GetInstance().App;

            CodeTorch.Web.FieldTemplates.BaseFieldTemplate f = null;

            switch (parameter.InputType)
            {
            case ScreenInputType.AppSetting:
                retVal = ConfigurationManager.AppSettings[parameter.InputKey];
                break;

            case ScreenInputType.Control:
                throw new NotSupportedException();

                //if (container == null)
                //{
                //    f = page.FindFieldRecursive(parameter.InputKey);
                //}
                //else
                //{
                //    f = page.FindFieldRecursive(container, parameter.InputKey);
                //}

                //if (f != null)
                //{
                //    retVal = f.Value;
                //}

                break;

            case ScreenInputType.ControlText:

                //if (container == null)
                //{
                //    f = page.FindFieldRecursive(parameter.InputKey);
                //}
                //else
                //{
                //    f = page.FindFieldRecursive(container, parameter.InputKey);
                //}

                //if (f != null)
                //{
                //    retVal = f.DisplayText;
                //}
                throw new NotSupportedException();

                break;

            case ScreenInputType.Cookie:
                retVal = HttpContext.Current.Request.Cookies[parameter.InputKey].Value;
                break;

            case ScreenInputType.File:
                //currently onlu supports storage to database
                if (HttpContext.Current.Request.ContentType.ToLower().Contains("multipart"))
                {
                    HttpPostedFile file = null;


                    if (HttpContext.Current.Request.Files.Count == 1)
                    {
                        //for refit support
                        file = HttpContext.Current.Request.Files[0] as HttpPostedFile;
                    }
                    else
                    {
                        file = HttpContext.Current.Request.Files[parameter.InputKey] as HttpPostedFile;
                    }
                    file = HttpContext.Current.Request.Files[parameter.InputKey] as HttpPostedFile;

                    if (file != null)
                    {
                        if (file.ContentLength > 0)
                        {
                            DocumentService documentService = DocumentService.GetInstance();

                            if (String.IsNullOrEmpty(parameter.Default))
                            {
                                retVal = ReadFully(file.InputStream);
                            }
                            else
                            {
                                DocumentRepository repo = DocumentRepository.GetByName(parameter.Default);

                                if (repo == null)
                                {
                                    throw new Exception(String.Format("Parameter {0} is assigned to a missing document repository  - {1}. Please check configuration.", parameter.Name, parameter.Default));
                                }

                                IDocumentProvider documentProvider = documentService.GetProvider(repo);
                                if (documentProvider == null)
                                {
                                    throw new Exception(String.Format("Parameter {0} is assigned to document repository  - {1}. The provider for this repository could not be found. Please check configuration", parameter.Name, parameter.Default));
                                }

                                // AppendDocumentID(DocumentID);
                                Document document = new Document();    //need to clone from config

                                document.FileName    = file.FileName;
                                document.ContentType = file.ContentType;

                                if (String.IsNullOrEmpty(document.ContentType))
                                {
                                    document.ContentType = "application / octet - stream";
                                }

                                document.Size       = Convert.ToInt32(file.ContentLength);
                                document.Stream     = file.InputStream;
                                document.EntityID   = "TEMP";
                                document.EntityType = "TEMP";


                                document.Settings.Add(new Setting("ModifiedBy", "SYSTEM"));

                                //perform actual upload
                                document.ID = documentProvider.Upload(document);


                                retVal = document.ID;
                            }
                        }
                    }
                }

                break;

            case ScreenInputType.Form:
                retVal = HttpContext.Current.Request.Form[parameter.InputKey];
                break;

            case ScreenInputType.Header:
                retVal = HttpContext.Current.Request.Headers[parameter.InputKey];
                break;

            case ScreenInputType.QueryString:
                retVal = HttpContext.Current.Request.QueryString[parameter.InputKey];
                break;

            case ScreenInputType.Session:
                retVal = HttpContext.Current.Session[parameter.InputKey];
                break;

            case ScreenInputType.Special:
                switch (parameter.InputKey.ToLower())
                {
                case "null":
                    retVal = null;
                    break;

                case "newid":
                    retVal = newID;
                    break;

                case "dbnull":
                    retVal = DBNull.Value;
                    break;

                case "username":

                    retVal = UserIdentityService.GetInstance().IdentityProvider.GetUserName();

                    break;

                case "hostheader":
                    retVal = HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
                    break;

                case "applicationpath":
                    retVal = HttpContext.Current.Request.ApplicationPath;
                    break;

                case "urlsegment":
                    try
                    {
                        retVal = this.RouteData.Values[parameter.Default];
                    }
                    catch { }
                    break;

                case "absoluteapplicationpath":
                    retVal = String.Format("{0}://{1}{2}",
                                           HttpContext.Current.Request.Url.Scheme,
                                           HttpContext.Current.Request.ServerVariables["HTTP_HOST"],
                                           ((HttpContext.Current.Request.ApplicationPath == "/") ? String.Empty : HttpContext.Current.Request.ApplicationPath));

                    break;
                }
                break;

            case ScreenInputType.User:
                try
                {
                    List <string> profileProperties = CodeTorch.Core.Configuration.GetInstance().App.ProfileProperties;
                    int           propertyIndex     = Enumerable.Range(0, profileProperties.Count).First(i => profileProperties[i].ToLower() == parameter.InputKey.ToLower());

                    FormsIdentity             identity = (FormsIdentity)HttpContext.Current.User.Identity;
                    FormsAuthenticationTicket ticket   = identity.Ticket;

                    retVal = ticket.UserData.Split('|')[propertyIndex];
                }
                catch { }
                break;

            case ScreenInputType.Constant:
                retVal = parameter.InputKey;
                break;

            case ScreenInputType.ServerVariables:
                retVal = HttpContext.Current.Request.ServerVariables[parameter.InputKey];
                break;
            }

            if (
                (parameter.InputType != ScreenInputType.Special) &&
                (parameter.InputType != ScreenInputType.File)
                )
            {
                if (retVal == null)
                {
                    retVal = parameter.Default;
                }
            }

            return(retVal);
        }
Пример #3
0
        public static object GetParameterInputValue(BasePage page, IScreenParameter parameter, Control container)
        {
            object retVal = null;
            App    app    = CodeTorch.Core.Configuration.GetInstance().App;

            CodeTorch.Web.FieldTemplates.BaseFieldTemplate f = null;

            switch (parameter.InputType)
            {
            case ScreenInputType.AppSetting:
                retVal = ConfigurationManager.AppSettings[parameter.InputKey];
                break;

            case ScreenInputType.Control:


                if (container == null)
                {
                    f = page.FindFieldRecursive(parameter.InputKey);
                }
                else
                {
                    f = page.FindFieldRecursive(container, parameter.InputKey);
                }

                if (f != null)
                {
                    retVal = f.Value;
                }

                break;

            case ScreenInputType.ControlText:

                if (container == null)
                {
                    f = page.FindFieldRecursive(parameter.InputKey);
                }
                else
                {
                    f = page.FindFieldRecursive(container, parameter.InputKey);
                }

                if (f != null)
                {
                    retVal = f.DisplayText;
                }

                break;

            case ScreenInputType.Cookie:
                retVal = page.Request.Cookies[parameter.InputKey].Value;
                break;

            case ScreenInputType.Form:
                retVal = page.Request.Form[parameter.InputKey];
                break;

            case ScreenInputType.Header:
                retVal = page.Request.Headers[parameter.InputKey];
                break;

            case ScreenInputType.QueryString:
                retVal = page.Request.QueryString[parameter.InputKey];
                break;

            case ScreenInputType.Session:
                retVal = page.Session[parameter.InputKey];
                break;

            case ScreenInputType.Special:
                switch (parameter.InputKey.ToLower())
                {
                case "null":
                    retVal = null;
                    break;

                case "dbnull":
                    retVal = DBNull.Value;
                    break;

                case "username":
                    retVal = UserIdentityService.GetInstance().IdentityProvider.GetUserName();
                    break;

                case "hostheader":
                    retVal = HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
                    break;

                case "applicationpath":
                    retVal = HttpContext.Current.Request.ApplicationPath;
                    break;

                case "absoluteapplicationpath":
                    retVal = String.Format("{0}://{1}{2}",
                                           HttpContext.Current.Request.Url.Scheme,
                                           HttpContext.Current.Request.ServerVariables["HTTP_HOST"],
                                           ((HttpContext.Current.Request.ApplicationPath == "/") ? String.Empty : HttpContext.Current.Request.ApplicationPath));

                    break;
                }
                break;

            case ScreenInputType.User:
                try
                {
                    retVal = GetProfileProperty(parameter.InputKey);
                }
                catch { }
                break;

            case ScreenInputType.Constant:
                retVal = parameter.InputKey;
                break;

            case ScreenInputType.ServerVariables:
                retVal = HttpContext.Current.Request.ServerVariables[parameter.InputKey];
                break;
            }

            if (parameter.InputType != ScreenInputType.Special)
            {
                if (retVal == null)
                {
                    retVal = parameter.Default;
                }
            }

            return(retVal);
        }