private FieldOfInterestView MapToFieldOfInterestView(FieldOfInterest field)
        {
            string languageId;
            string description = DescriptionHelper.GetDescription(field.Descriptions, out languageId);

            return(new FieldOfInterestView
            {
                FieldOfInterestId = field.FieldOfInterestId,
                LanguageId = languageId,
                Description = description,
                Created = field.Created,
                CreatedBy = field.CreatedBy,
                Updated = field.Updated,
                UpdatedBy = field.UpdatedBy,
                RowVersion = field.RowVersion
            });
        }
Example #2
0
        private static void WriteDesc(string text, ICustomAttributeProvider method)
        {
            var desc = DescriptionHelper.GetDescription(method);

            if (!String.IsNullOrEmpty(desc))
            {
                text += " - ";
                text += desc;
            }
            Console.WriteLine(text);
            //на подумать, получается все равно криво
            //var rest = text.Length;
            //var begin = 0;
            //while (rest > 0) {
            //	var length = Math.Min(Math.Min(Console.WindowWidth - 1, 64), rest);
            //	var line = text.Substring(begin, length);
            //	if (begin > 0)
            //		Console.Write("    ");
            //	Console.WriteLine(line);
            //	begin += length;
            //	rest -= length;
            //}
        }
        private bool LoadPermissions()
        {
            bool isOK = true;

            try
            {
                // Open connection to repository and query group members
                logX.loggerX.InfoFormat("Retrieve Snapshot OS Permissions for user: {0}", m_name);

                using (SqlConnection connection = new SqlConnection(Program.gController.Repository.ConnectionString))
                {
                    // Open the connection.
                    connection.Open();

                    string sidString = "0x";
                    foreach (Byte sidchar in m_sid)
                    {
                        sidString += sidchar.ToString("X2");
                    }
                    string query = string.Format(QueryOsObjectPermissions, m_snapshotId, sidString);

                    //Get Permissions
                    using (SqlCommand cmd = new SqlCommand(query, connection))
                    {
                        cmd.CommandType = CommandType.Text;

                        SqlDataAdapter da = new SqlDataAdapter(cmd);
                        DataSet        ds = new DataSet();
                        da.Fill(ds);

                        ds.Tables[0].Columns.Add(colTextRights);
                        ds.Tables[0].Columns.Add(colTextAuditFlags);
                        ds.Tables[0].Columns.Add(colTextAccessType);
                        DataView dv = new DataView(ds.Tables[0]);
                        dv.Sort = colName;

                        _grid.BeginUpdate();
                        _grid.SetDataBinding(dv, null);
                        _grid.EndUpdate();

                        foreach (DataRowView drv in dv)
                        {
                            string objectType;
                            string rights = string.Empty;

                            switch (drv[colType].ToString().Trim())
                            {
                            case OsObjectType.DB:
                                objectType = DescriptionHelper.GetDescription(typeof(OsObjectType), "DB");
                                if (drv[colRights] != DBNull.Value)
                                {
                                    rights = ((FileSystemRights)drv[colRights]).ToString();
                                }
                                break;

                            case OsObjectType.Disk:
                                objectType = DescriptionHelper.GetDescription(typeof(OsObjectType), "Disk");
                                if (drv[colRights] != DBNull.Value)
                                {
                                    rights = ((FileSystemRights)drv[colRights]).ToString();
                                }
                                break;

                            case OsObjectType.File:
                                objectType = DescriptionHelper.GetDescription(typeof(OsObjectType), "File");
                                if (drv[colRights] != DBNull.Value)
                                {
                                    rights = ((FileSystemRights)drv[colRights]).ToString();
                                }
                                break;

                            case OsObjectType.FileDirectory:
                                objectType = DescriptionHelper.GetDescription(typeof(OsObjectType), "FileDirectory");
                                if (drv[colRights] != DBNull.Value)
                                {
                                    rights = ((FileSystemRights)drv[colRights]).ToString();
                                }
                                break;

                            case OsObjectType.InstallDirectory:
                                objectType = DescriptionHelper.GetDescription(typeof(OsObjectType), "InstallDirectory");
                                if (drv[colRights] != DBNull.Value)
                                {
                                    rights = ((FileSystemRights)drv[colRights]).ToString();
                                }
                                break;

                            case OsObjectType.RegistryKey:
                                objectType = DescriptionHelper.GetDescription(typeof(OsObjectType), "RegistryKey");
                                if (drv[colRights] != DBNull.Value)
                                {
                                    rights = ((RegistryRights)drv[colRights]).ToString();
                                }
                                break;

                            default:
                                logX.loggerX.Warn("Warning - unknown OS Object Type encountered", drv[colType]);
                                objectType = DescriptionHelper.GetDescription(typeof(OsObjectType), "Unknown");
                                rights     = "Unknown";
                                break;
                            }
                            drv[colType]       = objectType;
                            drv[colTextRights] = rights;

                            //decode Audit flags
                            string auditFlags = string.Empty;

                            if (drv[colAuditFlags] != DBNull.Value)
                            {
                                foreach (int flag in Enum.GetValues(typeof(AuditFlags)))
                                {
                                    //skip 0 because that is the None value which is not displayed in the security settings
                                    if (flag > 0 && ((int)drv[colAuditFlags] & flag) == flag)
                                    {
                                        auditFlags += (auditFlags.Length > 0 ? ", " : string.Empty) +
                                                      DescriptionHelper.GetEnumDescription((AuditFlags)flag);
                                    }
                                }
                            }
                            drv[colTextAuditFlags] = auditFlags;

                            //decode access types
                            string access = drv[colAccessType].ToString();
                            if (drv[colAccessType] != DBNull.Value)
                            {
                                foreach (int flag in Enum.GetValues(typeof(AccessControlType)))
                                {
                                    if ((int)drv[colAccessType] == flag)
                                    {
                                        // These cannot be combined
                                        access = DescriptionHelper.GetEnumDescription((AccessControlType)flag);
                                        break;
                                    }
                                }
                            }
                            drv[colTextAccessType] = access;
                        }
                    }
                    _label_Header.Text = string.Format("OS Objects ({0} items)", _grid.Rows.Count);
                }
            }
            catch (SqlException ex)
            {
                logX.loggerX.Info("ERROR - unable to load OS Permissions from the selected Snapshot.", ex);
                Utility.MsgBox.ShowError(Utility.ErrorMsgs.OSPermissionsCaption, ex.Message);
                isOK = false;
            }
            catch (Exception ex)
            {
                isOK = false;
                logX.loggerX.Info("ERROR - unable to load OS Permissions from the selected Snapshot.", ex);
                Utility.MsgBox.ShowError(Utility.ErrorMsgs.OSPermissionsCaption, Utility.ErrorMsgs.CantGetSnapshot);
            }
            return(isOK);
        }