Exemple #1
0
        protected bool IsActiveConfiguration(Durados.View view, object data)
        {
            if (view != null && !view.Fields.ContainsKey("Active"))
            {
                throw new DuradosException("Missing Active Config Field.");
            }
            if (data != null && !(data is  DataRow))
            {
                throw new DuradosException("Missing data row for xml document file name.");
            }

            Durados.Field field        = view.Fields["Active"];
            string        activeConfig = field.GetValue((DataRow)data);

            bool isActiveConfig = false;;

            //string outputXmlFileName = newFile;
            if (!string.IsNullOrEmpty(activeConfig) && field is ColumnField && bool.TryParse(((ColumnField)field).ConvertFromString(activeConfig).ToString(), out isActiveConfig))
            {
                return(isActiveConfig);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
 public override string GetElementForTableView(Durados.Field field, DataRow row, string guid)
 {
     if (field.FieldType == FieldType.Children && ((ChildrenField)field).ChildrenHtmlControlType != ChildrenHtmlControlType.CheckList && row.IsNull("EngRevisionId"))
     {
         return(string.Empty);
     }
     else
     {
         return(base.GetElementForTableView(field, row, guid));
     }
 }
Exemple #3
0
 private static bool HasPrimary(Durados.Web.Mvc.View view, Durados.Field field)
 {
     if (view.Database.Views.ContainsKey(field.RelatedViewName))
     {
         return(view.Database.Views[field.RelatedViewName].PrimaryKeyFileds.Length > 0);
     }
     else
     {
         return(false);
     }
 }
Exemple #4
0
        public virtual string ToFriendlyString()
        {
            string s = string.Empty;

            foreach (Field field in Fields.Values)
            {
                string displayName = string.Empty;
                foreach (Durados.View view in Map.Database.Views.Values)
                {
                    if (view.Fields.ContainsKey(field.Name))
                    {
                        Durados.Field f = view.Fields[field.Name];
                        switch (f.FieldType)
                        {
                        case FieldType.Parent:
                            displayName = ((Durados.ParentField)f).DisplayName;
                            break;

                        case FieldType.Children:
                            displayName = ((ChildrenField)f).GetRelatedParentField().DisplayName;


                            break;

                        default:
                            throw new NotSupportedException();
                        }
                        break;
                    }
                }
                if (displayName == string.Empty)
                {
                    displayName = field.Name;
                }
                s += displayName;
                s += "=";
                s += field.Value.ToString();
                s += " and ";
            }

            return(s.EndsWith("and ") ? s.Remove(s.Length - 5) : s);
        }
Exemple #5
0
        public override IHttpActionResult Post()
        {
            IDictionary <string, object> values = Request.GetRouteData().Values;

            if (!values.ContainsKey("viewName"))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, Messages.ViewNameIsMissing)));
            }
            if (!values.ContainsKey("fieldName"))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, Messages.FieldNameIsMissing)));
            }
            string viewName  = values["viewName"].ToString();
            string fieldName = values["fieldName"].ToString();

            View view = GetView(viewName);

            if (view == null)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.ViewNameNotFound, viewName))));
            }

            Durados.Field[] fields = view.GetFieldsByJsonName(fieldName);
            if (fields == null || fields.Length == 0)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.FieldNameNotFound, fieldName))));
            }


            Durados.Field field = fields[0];

            if (field.FieldType != Durados.FieldType.Column || field.GetColumnFieldType() != Durados.ColumnFieldType.String)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.TheFieldMustBeTextual, fieldName))));
            }



            return(base.Post());
        }
Exemple #6
0
        private List <DateTime?> GetDates(ColumnField field, List <string> fields, DataRow dataRow)
        {
            if (field == null)
            {
                throw new MissingFieldException("Field does not exists!");
            }
            else
            {
                List <DateTime?> dates = new List <DateTime?>();
                foreach (string fieldName in fields)
                {
                    if (!field.View.Fields.ContainsKey(fieldName))
                    {
                        dates.Add(null);
                    }
                    else
                    {
                        Durados.Field dateField = field.View.Fields[fieldName];

                        string strDate = dateField.GetValue(dataRow);

                        DateTime date = new DateTime();

                        bool isValidDate = DateTime.TryParse(strDate, out date);

                        if (isValidDate && date > NADate)
                        {
                            dates.Add(date);
                        }
                        else
                        {
                            dates.Add(null);
                        }
                    }
                }
                return(dates);
            }
        }
Exemple #7
0
        public virtual string GetParentFiterFieldName(Database database)
        {
            Durados.ParentField parentField = null;
            foreach (Field field in Fields.Values)
            {
                foreach (Durados.View view in database.Views.Values)
                {
                    if (view.Fields.ContainsKey(field.Name))
                    {
                        Durados.Field f = view.Fields[field.Name];
                        switch (f.FieldType)
                        {
                        case FieldType.Parent:
                            break;

                        case FieldType.Children:
                            parentField = ((ChildrenField)f).GetRelatedParentField();
                            break;

                        case FieldType.Column:
                            return(field.Name);

                        default:
                            throw new NotSupportedException();
                        }
                        break;
                    }
                }
            }

            if (parentField == null)
            {
                return(string.Empty);
            }

            return(parentField.Name);
        }
Exemple #8
0
        public void LoadValue(Dictionary <string, object> values, System.Data.DataRow dataRow, Durados.View view, Durados.Field field, string dynastyPath, string prefix, string postfix, Dictionary <string, Durados.Workflow.DictionaryField> dicFields, string internalDynastyPath)
        {
            string name         = prefix + dynastyPath + field.DisplayName + postfix;
            string InternalName = prefix + internalDynastyPath + field.Name + postfix;
            string value        = view.GetDisplayValue(field.Name, dataRow);

            if (!values.ContainsKey(name))
            {
                values.Add(name, value);
                dicFields.Add(InternalName, new Durados.Workflow.DictionaryField {
                    DisplayName = name, Type = field.DataType, Value = value
                });
            }
            if (field.FieldType == Durados.FieldType.Column && ((ColumnField)field).Upload != null)
            {
                if (dataRow.Table.Columns.Contains(field.Name))
                {
                    dataRow.Table.Columns[field.Name].ExtendedProperties["ImagePath"] = ((ColumnField)field).GetUploadPath();
                }
            }
        }
Exemple #9
0
 public virtual string GetFieldValue(Durados.Field field, string pk)
 {
     return(field.GetValue(pk));
 }
Exemple #10
0
        [HttpPost] // This is from System.Web.Http, and not from System.Web.Mvc
        public HttpResponseMessage Upload(string viewName, string fieldName)
        {
            if (string.IsNullOrEmpty(viewName))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, Messages.ViewNameIsMissing));
            }

            Durados.Web.Mvc.View view = GetView(viewName);
            if (view == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.ViewNameNotFound, viewName)));
            }

            if (string.IsNullOrEmpty(fieldName))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, Messages.FieldNameIsMissing));
            }

            Durados.Field[] fields = view.GetFieldsByJsonName(fieldName);
            if (fields.Length == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.FieldNameNotFound, fieldName)));
            }

            Durados.Field field = fields[0];

            if (!(field.FieldType == Durados.FieldType.Column && ((ColumnField)field).FtpUpload != null))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.UploadNotFound, fieldName)));
            }

            Durados.Web.Mvc.ColumnField columnField = (Durados.Web.Mvc.ColumnField)field;

            //if (!Request.Content.IsMimeMultipartContent())
            //{
            //    this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
            //}

            //var provider = GetMultipartProvider();
            //var result = Request.Content.ReadAsMultipartAsync(provider);
            //var result = await Request.Content.ReadAsMultipartAsync();

            // On upload, files are given a generic name like "BodyPart_26d6abe1-3ae1-416a-9429-b35f15e6e5d5"
            // so this is how you can get the original file name
            //var originalFileName = GetDeserializedFileName(result.FileData.First());

            //string strFileName = originalFileName;

            // uploadedFileInfo object will give you some additional stuff like file length,
            // creation time, directory name, a few filesystem methods etc..
            //var uploadedFileInfo = new FileInfo(result.FileData.First().LocalFileName);

            //string strExtension = Path.GetExtension(originalFileName).ToLower().TrimStart('.');

            List <object> files = new List <object>();

            foreach (string key in System.Web.HttpContext.Current.Request.Files.AllKeys)
            {
                var file = System.Web.HttpContext.Current.Request.Files[key];

                string strFileName = Path.GetFileName(file.FileName);

                try
                {
                    string strExtension = Path.GetExtension(strFileName).ToLower().TrimStart('.');

                    if (!FtpUploadValidExtension(strExtension))
                    {
                        //return Request.CreateResponse(HttpStatusCode.UnsupportedMediaType, Messages.InvalidFileType);
                        files.Add(new { fileName = strFileName, success = false, error = "Invalid file type" });
                        continue;
                    }

                    if (!string.IsNullOrEmpty(columnField.FtpUpload.FileAllowedTypes))
                    {
                        string[] exts = columnField.FtpUpload.FileAllowedTypes.Split(',');

                        bool valid = false;

                        foreach (string ext in exts)
                        {
                            if (ext.Trim().Equals(strExtension))
                            {
                                valid = true;
                                break;
                            }
                        }
                        if (!valid)
                        {
                            files.Add(new { fileName = strFileName, success = false, error = "Invalid file type" });
                            continue;
                            //return Request.CreateResponse(HttpStatusCode.UnsupportedMediaType, string.Format(Messages.InvalidFileType2, columnField.DisplayName, columnField.FtpUpload.FileAllowedTypes));
                        }
                    }

                    //float fileSize = (uploadedFileInfo.Length / 1024) / 1000;
                    float fileSize = (file.ContentLength / 1024) / 1000;

                    if (!FtpUploadValidSize(columnField, fileSize))
                    {
                        files.Add(new { fileName = strFileName, success = false, error = "The file is too big" });
                        continue;

                        //throw new Exception("The file has exceeded the size limit.");
                    }

                    if (!FtpUploadValidFolderSize(columnField, fileSize))
                    {
                        files.Add(new { fileName = strFileName, success = false, error = "Total files exceeded quota" });
                        continue;

                        //throw new Exception("The folder has exceeded the size limit.");
                    }

                    if (columnField.FtpUpload.FileMaxSize > 0)
                    {
                        if (fileSize > columnField.FtpUpload.FileMaxSize)
                        {
                            //throw new Exception("File too big in field [" + field.DisplayName + "].<br><br>Max Allowed size: " + columnField.FtpUpload.FileMaxSize + " MB");
                            files.Add(new { fileName = strFileName, success = false, error = "The file is too big" });
                            continue;
                        }
                    }

                    string strSaveLocation = string.Empty;

                    string src = string.Empty;

                    if (columnField.FtpUpload.StorageType == StorageType.Azure)
                    {
                        src = SaveUploadedFileToAzure(columnField, strFileName, file.ContentType, file.InputStream);
                    }
                    else if (columnField.FtpUpload.StorageType == StorageType.Aws)
                    {
                        src = SaveUploadedFileToAws(columnField, strFileName, file.ContentType, file.InputStream);
                    }
                    else
                    {
                        SaveUploadedFileToFtp(columnField, strFileName, file.ContentType, file.InputStream);

                        if (columnField.FtpUpload.StorageType != StorageType.Azure)
                        {
                            src = columnField.FtpUpload.DirectoryVirtualPath.TrimEnd('/') + "/" + ((string.IsNullOrEmpty(columnField.FtpUpload.DirectoryBasePath)) ? string.Empty : (columnField.FtpUpload.DirectoryBasePath.TrimStart('/').TrimEnd('/') + "/")) + strFileName;
                        }
                        else
                        {
                            src = System.Web.HttpContext.Current.Server.UrlEncode((new Durados.Web.Mvc.UI.ColumnFieldViewer()).GetDownloadUrl(columnField, string.Empty));
                        }
                    }

                    files.Add(new { fileName = strFileName, url = src, success = true });
                }
                catch (Exception exception)
                {
                    files.Add(new { fileName = strFileName, success = false, error = exception.Message });
                    continue;
                }
            }

            // Through the request response you can return an object to the Angular controller
            // You will be able to access this in the .success callback through its data attribute
            // If you want to send something to the .error callback, use the HttpStatusCode.BadRequest instead
            return(this.Request.CreateResponse(HttpStatusCode.OK, new { files = files }));
        }
Exemple #11
0
 public override string GetElementForReport(Durados.Field field, string guid)
 {
     return(GetElementForCreate(field, guid));
 }
Exemple #12
0
        public void EditPreview(string configViewName, string property, string value, string pk, string guid, out Durados.Web.Mvc.View view)
        {
            Durados.Web.Mvc.Map             previewMap   = Maps.Instance.GetMap();
            Durados.DataAccess.ConfigAccess configAccess = new DataAccess.ConfigAccess();
            view = null;

            if (configViewName == "Page" && guid == PageGuid)
            {
                try
                {
                    view = null;
                    Page page = Maps.Instance.GetMap().Database.Pages[Convert.ToInt32(pk)];
                    System.Reflection.PropertyInfo propertyInfo = page.GetType().GetProperty(property);
                    object value2;
                    if (propertyInfo.PropertyType.BaseType.FullName == "System.Enum")
                    {
                        value2 = Enum.Parse(propertyInfo.PropertyType, value);
                    }
                    else
                    {
                        value2 = Convert.ChangeType(value, propertyInfo.PropertyType);
                    }
                    propertyInfo.SetValue(page, value2, null);
                    Save((View)previewMap.GetConfigDatabase().Views["Page"], property, value2, pk);
                }
                catch (Exception ex)
                {
                    throw new DuradosException("Failed to set value to field property.", ex);
                }
            }
            else if (configViewName == "View")
            {
                string viewName = configAccess.GetViewNameByPK(pk, previewMap.GetConfigDatabase().ConnectionString);
                if (string.IsNullOrEmpty(viewName))
                {
                    // previewMap.Logger.Log("Admmin", "PreviewEdit", "EditPreview", null, 15, "viewName are null or empty.");
                    throw new DuradosException("viewName are null or empty or not exists.");
                }

                if (!previewMap.Database.Views.ContainsKey(viewName))
                {
                    //previewMap.Logger.Log("Admmin", "PreviewEdit", "EditPreview", null, 15, "viewName are not contained in Views.");
                    throw new DuradosException("viewName are not contained in Views.");
                }

                view = (Durados.Web.Mvc.View)previewMap.Database.Views[viewName];

                try
                {
                    System.Reflection.PropertyInfo propertyInfo = view.GetType().GetProperty(property);
                    object value2;
                    if (propertyInfo.PropertyType.BaseType.FullName == "System.Enum")
                    {
                        value2 = Enum.Parse(propertyInfo.PropertyType, value);
                    }
                    else
                    {
                        value2 = Convert.ChangeType(value, propertyInfo.PropertyType);
                    }
                    propertyInfo.SetValue(view, value2, null);
                    if (guid == PageGuid)
                    {
                        Save((View)previewMap.GetConfigDatabase().Views["View"], property, value2, pk);
                    }
                }
                catch (Exception ex)
                {
                    throw new DuradosException("Failed to set value to field property.", ex);
                }
            }
            else if (configViewName == "Field")
            {
                string fieldName = configAccess.GetFieldNameByPK(pk, previewMap.GetConfigDatabase().ConnectionString);
                string viewPK    = configAccess.GetViewPKByFieldPK(pk, previewMap.GetConfigDatabase().ConnectionString);
                string viewName  = configAccess.GetViewNameByPK(viewPK, previewMap.GetConfigDatabase().ConnectionString);
                if (string.IsNullOrEmpty(viewName) || string.IsNullOrEmpty(fieldName))
                {
                    throw new DuradosException("fieldName or viewName are null or empty.");
                    //previewMap.Logger.Log("Admmin","PreviewEdit","EditPreview",null,15,"fieldName or viewName are null or empty.");
                }

                if (!previewMap.Database.Views.ContainsKey(viewName) || !previewMap.Database.Views[viewName].Fields.ContainsKey(fieldName))
                {
                    throw new DuradosException("fieldName or viewName are not contained in file.");
                    //previewMap.Logger.Log("Admmin", "PreviewEdit", "EditPreview", null, 15, "fieldName or viewName are not contained in file.");
                }

                Durados.Field field = previewMap.Database.Views[viewName].Fields[fieldName];

                try
                {
                    System.Reflection.PropertyInfo propertyInfo = field.GetType().GetProperty(property);
                    object value2;
                    if (propertyInfo.PropertyType.BaseType.FullName == "System.Enum")
                    {
                        value2 = Enum.Parse(propertyInfo.PropertyType, value);
                    }
                    else
                    {
                        value2 = Convert.ChangeType(value, propertyInfo.PropertyType);
                    }
                    propertyInfo.SetValue(field, value2, null);
                }
                catch (Exception ex)
                {
                    throw new DuradosException("Failed to set value to field property.", ex);
                }
            }
        }
Exemple #13
0
 public override bool IsSortable(Durados.Field field, string guid)
 {
     return(false);
 }
Exemple #14
0
 private string GetFieldNameWithSpan(Durados.Field field)
 {
     return(GetFieldName(field) + FieldIdSpan + field.View.Name + "," + field.Name + EndFieldIdSpan);
 }
Exemple #15
0
 private string GetFieldName(Durados.Field field)
 {
     return(field.DisplayName);
 }