Ejemplo n.º 1
0
 /// <summary>
 /// Retrieves users from the Backup Store in a UserRows object. (UserRows are based off of the ULControl.CurrentHeaderRow property.)
 /// </summary>
 /// <returns>A UserRow object.</returns>
 static public Task <UserRows> GetUsersFromStore()
 {
     return(Task.Run(async() =>
     {
         try
         {
             string StorePath = Config.Settings["MigrationStorePath"];
             Logger.Information("Listing users from store: " + StorePath + "...");
             UserRows rows = new UserRows();
             int count = 0;
             DirectoryInfo[] directories = new DirectoryInfo(StorePath).GetDirectories();
             foreach (DirectoryInfo directory in directories)
             {
                 UserRow row = await GetUserFromStore(ULControl.CurrentHeaderRow, directory.Name);
                 if (row == null)
                 {
                     Logger.Warning("Skipping ID: " + directory.Name);
                     continue;
                 }
                 rows.Add(row);
                 Logger.UpdateProgress((int)(((float)++count / directories.Length) * 100));
                 Logger.Verbose("Found: " + row[ULColumnType.NTAccount]);
             }
             Logger.Success("Users listed successfully.");
             return rows;
         }
         catch (Exception e)
         {
             Logger.Exception(e, "Failed to list users from store.");
             return null;
         }
     }));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Retrieves users' properties from host based on the ULControl.CurrentHeaderRow property.
 /// </summary>
 /// <param name="Host">Host to get information from.</param>
 /// <returns>UserRows.</returns>
 public static Task <UserRows> GetUsersFromHost(string Host)
 {
     return(Task.Run(async() =>
     {
         try
         {
             UserRows rows = new UserRows();
             RegistryKey remoteReg = null;
             if (IsHostThisMachine(Host))
             {
                 remoteReg = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default);
             }
             else
             {
                 remoteReg = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Host);
             }
             RegistryKey profileList = remoteReg.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", false);
             Logger.Information("Getting list of users on: " + Host + "...");
             GetLocalUsersSIDsFromHost(Host);
             string[] SIDs = profileList.GetSubKeyNames();
             int count = 0;
             foreach (string SID in SIDs)
             {
                 if (Main.Canceled)
                 {
                     break;
                 }
                 UserRow row = await GetUserFromHost(ULControl.CurrentHeaderRow, Host, SID);
                 Logger.UpdateProgress((int)(((float)++count / SIDs.Length) * 100));
                 if (row != null)
                 {
                     rows.Add(row);
                 }
             }
             remoteReg.Close();
             if (Main.Canceled)
             {
                 Logger.Warning("Listing users was canceled.");
                 return null;
             }
             Logger.Success("Users listed successfully.");
             return rows;
         }
         catch (System.Security.SecurityException e)
         {
             Logger.Exception(e, "Failed to get a list of users. Please make sure the user \"" + Environment.UserDomainName + "\\" + Environment.UserName + "\" is an administrator on the host: " + Host);
             return null;
         }
         catch (Exception e)
         {
             Logger.Exception(e, "Failed to get a list of users. Please make sure that the specified host is valid and online, also make sure the \"Remote Registry\" service is enabled and running on the specified host: " + Host);
             return null;
         }
     }));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// This event will fire whenever the btnListStore is clicked. This will refresh or re-list the listUsers control with users from the store.
        /// </summary>
        private async void BtnListStore_Click(object sender, EventArgs e)
        {
            Running = RunningTask.Unknown;
            miAddRemoveCol.Enabled = true;
            lblUserList.Text       = "Users in Migration Store:";
            listUsers.SetViewMode(Config.Settings["ULViewMode"]);
            listUsers.SetColumns(ULControl.HeaderRowStoreSource, Config.Settings["ULStoreColumns"]);
            CurrentUserRows = await Misc.GetUsersFromStore();

            listUsers.SetRows(CurrentUserRows, CurrentSortColumn[ListSources.MigrationStore], CurrentSortDirection[ListSources.MigrationStore]);
            CurrentListSource = ListSources.MigrationStore;
            Running           = RunningTask.None;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This event will fire whenever the btnListSource is clicked. This will refresh or re-list the listUsers control with users from the source computer.
        /// </summary>
        private async void BtnListSource_Click(object sender, EventArgs e)
        {
            Running = RunningTask.Unknown;
            miAddRemoveCol.Enabled = true;
            listUsers.SetViewMode(Config.Settings["ULViewMode"]);
            listUsers.SetColumns(ULControl.HeaderRowComputerSource, Config.Settings["ULSourceColumns"]);
            lblUserList.Text = "Users on Source Computer:";
            CurrentUserRows  = await Misc.GetUsersFromHost(tbSourceComputer.Text);

            listUsers.SetRows(CurrentUserRows, CurrentSortColumn[ListSources.SourceComputer], CurrentSortDirection[ListSources.SourceComputer]);
            CurrentListSource = ListSources.SourceComputer;
            Running           = RunningTask.None;
        }
Ejemplo n.º 5
0
        public override void DoLoginedHandlerWork(HttpContext context)
        {
            Message jsonMessage;

            jsonMessage = new Message()
            {
                Result     = false,
                TxtMessage = "权限验证失败,可能原因:\n1、数据中心通讯失败。\n2、系统管理员未与您分配对应操作权限。"
            };
            //获取操作类型AType:ADD,EDIT,DELETE
            string   AjaxType = context.Request.QueryString["AType"] == null ? string.Empty : context.Request.QueryString["AType"].ToString().ToUpper();
            IoT_User Info; View_UserMeter viewInfo;
            WCFServiceProxy <IUserManage> proxy = null;

            try
            {
                switch (AjaxType)
                {
                //查询用户
                case "QUERY":

                    CommonSearch <IoT_User> InfoSearch = new CommonSearch <IoT_User>();
                    string Where = "1=1 ";
                    Where += "AND CompanyID='" + loginOperator.CompanyID + "' ";
                    if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty)
                    {
                        Where += context.Request.Form["TWhere"].ToString();
                    }
                    SearchCondition sCondition = new SearchCondition()
                    {
                        TBName = "IoT_User", TFieldKey = "UserID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "UserID ASC", TWhere = Where
                    };
                    List <IoT_User> list = InfoSearch.GetList(ref sCondition, context);
                    jsonMessage = new Message()
                    {
                        Result     = true,
                        TxtMessage = JSon.ListToJson <IoT_User>(list, sCondition.TTotalCount)
                    };
                    break;

                //查询用户表具视图
                case "QUERYVIEW":

                    CommonSearch <View_UserMeter> InfoSearchView = new CommonSearch <View_UserMeter>();
                    Where  = "1=1 ";
                    Where += "AND CompanyID='" + loginOperator.CompanyID + "' ";
                    if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty)
                    {
                        Where += context.Request.Form["TWhere"].ToString();
                    }
                    sCondition = new SearchCondition()
                    {
                        TBName = "View_UserMeter", TFieldKey = "UserID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "UserID ASC", TWhere = Where
                    };
                    List <View_UserMeter> listView = InfoSearchView.GetList(ref sCondition, context);
                    jsonMessage = new Message()
                    {
                        Result     = true,
                        TxtMessage = JSon.ListToJson <View_UserMeter>(listView, sCondition.TTotalCount)
                    };
                    break;

                //查询临时用户
                case "QUERYTEMP":

                    CommonSearch <IoT_UserTemp> InfoSearchTemp = new CommonSearch <IoT_UserTemp>();
                    Where  = "1=1 ";
                    Where += "AND CompanyID='" + loginOperator.CompanyID + "' ";
                    if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty)
                    {
                        Where += context.Request.Form["TWhere"].ToString();
                    }
                    sCondition = new SearchCondition()
                    {
                        TBName = "IoT_UserTemp", TFieldKey = "MeterNo", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "MeterNo ASC", TWhere = Where
                    };
                    List <IoT_UserTemp> listTemp = InfoSearchTemp.GetList(ref sCondition, context);
                    jsonMessage = new Message()
                    {
                        Result     = true,
                        TxtMessage = JSon.ListToJson <IoT_UserTemp>(listTemp, sCondition.TTotalCount)
                    };
                    break;

                case "QUERYALARMPARM":
                    //TODO:查询用户当前设置的报警参数
                    CommonSearch <Iot_MeterAlarmPara> meterAlarmPara = new CommonSearch <Iot_MeterAlarmPara>();
                    viewInfo = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);

                    if (viewInfo.MeterNo != null && viewInfo.MeterNo.ToString().Trim() != string.Empty)
                    {
                        Where      = $"MeterNo = '{viewInfo.MeterNo.ToString().Trim()}'";
                        sCondition = new SearchCondition()
                        {
                            TBName = "Iot_MeterAlarmPara", TFieldKey = "MeterNo", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "MeterNo ASC", TWhere = Where
                        };
                        List <Iot_MeterAlarmPara> listMAP = meterAlarmPara.GetList(ref sCondition, context);
                        if (listMAP.Count == 1)
                        {
                            jsonMessage = new Message()
                            {
                                Result     = true,
                                TxtMessage = JsToJson.SerializeToJsonString(listMAP[0])
                            };
                        }
                        else
                        {
                            jsonMessage = new Message()
                            {
                                Result     = false,
                                TxtMessage = "没有找到配置数据。"
                            };
                        }
                    }
                    break;

                //单户创建
                case "ADD":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "cjyh_dhcj"))
                    {
                        Info           = new CommonModelFactory <IoT_User>().GetModelFromContext(context);
                        Info.CompanyID = base.loginOperator.CompanyID;
                        proxy          = new WCFServiceProxy <IUserManage>();
                        jsonMessage    = proxy.getChannel.Add(Info);
                    }
                    break;


                //编辑用户信息和表信息
                case "EDITUSERMETER":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "dagl_bjyh"))
                    {
                        viewInfo    = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);
                        proxy       = new WCFServiceProxy <IUserManage>();
                        jsonMessage = proxy.getChannel.EditUserMeter(viewInfo);
                    }
                    break;

                //删除用户信息和表信息
                case "DELETEUSERMETER":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "dagl_scyh"))
                    {
                        viewInfo    = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);
                        proxy       = new WCFServiceProxy <IUserManage>();
                        jsonMessage = proxy.getChannel.DeleteUserMeter(viewInfo);
                    }
                    break;

                //批量删除用户
                case "BATCHDELETE":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "dagl_scyh"))
                    {
                        viewInfo = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);
                        proxy    = new WCFServiceProxy <IUserManage>();

                        if (context.Request.Form["strNo"] != null && context.Request.Form["strNo"].ToString().Trim() != string.Empty)
                        {
                            string strNo = context.Request.Form["strNo"];

                            string[] arrNo = strNo.Split(',');

                            for (int i = 0; i < arrNo.Length; i++)
                            {
                                proxy.getChannel.BatchDeleteUserMeter(arrNo[i]);
                            }
                        }
                        jsonMessage = new Message()
                        {
                            Result     = true,
                            TxtMessage = "删除用户成功"
                        };
                    }
                    break;

                //批量excel导入
                case "BATCHIMPORT":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "cjyh_dhcj"))
                    {
                        viewInfo = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);
                        proxy    = new WCFServiceProxy <IUserManage>();

                        if (context.Request.Form["strNo"] != null && context.Request.Form["strNo"].ToString().Trim() != string.Empty)
                        {
                            string strNo = context.Request.Form["strNo"];

                            string[] arrNo = strNo.Split(',');

                            for (int i = 0; i < arrNo.Length; i++)
                            {
                                proxy.getChannel.BatchImport(arrNo[i]);
                            }
                        }
                        jsonMessage = new Message()
                        {
                            Result     = true,
                            TxtMessage = "导入用户成功"
                        };
                    }
                    break;

                //批量添加用户
                case "BATCHADD":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "cjyh_dhcj"))
                    {
                        viewInfo = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);
                        proxy    = new WCFServiceProxy <IUserManage>();

                        string street = "";
                        if (context.Request.Form["Street"] != null && context.Request.Form["Street"].ToString().Trim() != string.Empty)
                        {
                            street = context.Request.Form["Street"].ToString().Trim();
                        }
                        string community = "";
                        if (context.Request.Form["Community"] != null && context.Request.Form["Community"].ToString().Trim() != string.Empty)
                        {
                            community = context.Request.Form["Community"].ToString().Trim();
                        }
                        string meterType = "";
                        if (context.Request.Form["MeterType"] != null && context.Request.Form["MeterType"].ToString().Trim() != string.Empty)
                        {
                            meterType = context.Request.Form["MeterType"].ToString().Trim();
                        }

                        if (context.Request.Form["Rows"] != null && context.Request.Form["Rows"].ToString().Trim() != string.Empty)
                        {
                            UserRows    rows     = JsToJson.Deserialize <UserRows>(context.Request.Form["Rows"].ToString());
                            List <User> userlist = rows.Rows;

                            int     count = 0; string error = "";
                            Message tempM = null;
                            foreach (User u in userlist)
                            {
                                if (u.MeterNo.Trim() == "")
                                {
                                    tempM = new Message()
                                    {
                                        Result = false, TxtMessage = string.Format("UserID={0}的表号未填写\r", u.UserID)
                                    };
                                }
                                else
                                {
                                    IoT_User tempUser = new IoT_User();

                                    tempUser.UserID    = u.UserID;
                                    tempUser.UserName  = u.UserName;
                                    tempUser.Address   = u.Address;
                                    tempUser.Community = community;
                                    tempUser.Street    = street;
                                    tempUser.CompanyID = loginOperator.CompanyID;
                                    tempUser.State     = '1';

                                    IoT_Meter tempMeter = new IoT_Meter();
                                    tempMeter.MeterType = meterType;
                                    tempMeter.MeterNo   = u.MeterNo;
                                    tempMeter.CompanyID = loginOperator.CompanyID;
                                    tempM = proxy.getChannel.BatchAddUserMeter(tempUser, tempMeter);
                                }
                                if (tempM.Result)
                                {
                                    count++;
                                }
                                else
                                {
                                    error = tempM.TxtMessage;
                                }
                            }
                            if (count > 0)
                            {
                                jsonMessage = new Message()
                                {
                                    Result     = true,
                                    TxtMessage = "批量添加用户" + count + "个成功," + (userlist.Count - count) + "个失败,失败原因:" + error
                                };
                            }
                            else
                            {
                                jsonMessage = new Message()
                                {
                                    Result     = false,
                                    TxtMessage = "批量添加用户失败"
                                };
                            }
                        }
                    }
                    break;

                default:
                    jsonMessage = new Message()
                    {
                        Result     = false,
                        TxtMessage = "操作未定义。"
                    };
                    break;
                }
            }
            catch (Exception ex) {
                jsonMessage = new Message()
                {
                    Result     = false,
                    TxtMessage = ex.Message
                };
            }
            finally
            {
                if (proxy != null)
                {
                    proxy.CloseChannel();
                }
            }
            context.Response.Write(JSon.TToJson <Message>(jsonMessage));
        }
Ejemplo n.º 6
0
 public static void SetRows(this ListView Owner, UserRows Rows, ULColumnType SortColumn = ULColumnType.Tag, ULSortDirection SortDirection = ULSortDirection.Ascending)
 {
     Owner.BeginUpdate();
     Owner.SuspendLayout();
     Owner.Items.Clear();
     foreach (ColumnHeader colHead in Owner.Columns)
     {
         ULColumnType colType = (ULColumnType)colHead.Tag;
         string       arrow   = "";
         if (colType == SortColumn)
         {
             if (SortDirection == ULSortDirection.Ascending)
             {
                 arrow = " ↑";
             }
             if (SortDirection == ULSortDirection.Descending)
             {
                 arrow = " ↓";
             }
         }
         colHead.Text = CurrentHeaderRow[colType] + arrow;
     }
     if (Rows != null)
     {
         Rows.Sort(delegate(UserRow x, UserRow y) {
             if (!x.ContainsKey(SortColumn) && !y.ContainsKey(SortColumn))
             {
                 return(0);
             }
             if (!x.ContainsKey(SortColumn) || x[SortColumn] == null)
             {
                 return(-1);
             }
             if (!y.ContainsKey(SortColumn) || y[SortColumn] == null)
             {
                 return(1);
             }
             if (x[SortColumn] == y[SortColumn])
             {
                 return(0);
             }
             long intX, intY = 0;
             if (long.TryParse(x[SortColumn], out intX) && long.TryParse(y[SortColumn], out intY))
             {
                 if (intX > intY)
                 {
                     return(-1);
                 }
                 if (intX < intY)
                 {
                     return(1);
                 }
             }
             return(x[SortColumn].CompareTo(y[SortColumn]));
         });
         if (SortDirection == ULSortDirection.Ascending)
         {
             Rows.Reverse();
         }
         foreach (UserRow row in Rows)
         {
             ListViewItem lvRow = null;
             bool         first = true;
             foreach (KeyValuePair <ULColumnType, string> column in row)
             {
                 if (column.Key == ULColumnType.Tag)
                 {
                     continue;
                 }
                 string value = ConvertColumnValue(column);
                 if (first)
                 {
                     lvRow          = Owner.Items.Add(value);
                     lvRow.ImageKey = "user";
                     lvRow.Tag      = row[ULColumnType.Tag];
                     first          = false;
                 }
                 else
                 {
                     lvRow.SubItems.Add(value);
                 }
             }
         }
     }
     Owner.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
     Owner.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
     Owner.ResumeLayout();
     Owner.EndUpdate();
 }