Esempio n. 1
0
        private void checkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgvTotal.SelectedRows)
            {
                string path = row.Cells[3].Value.ToString().Trim();

                using (var impersonation = new ImpersonatedUser("itadmin", "kmhk.local", "Ed@a*9kj"))
                {
                    if (!File.Exists(path))
                    {
                        row.Cells[6].Value = "Not exists";
                    }
                    else
                    {
                        try
                        {
                            FileSystemSecurity security = File.GetAccessControl(path);

                            row.Cells[6].Value = "OK";
                        }
                        catch
                        {
                            row.Cells[6].Value = "No Permission";
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void btnSize_Click(object sender, EventArgs e)
        {
            double size = 0;

            string[] sizes = { "B", "KB", "MB", "GB" };

            foreach (DiscIdleList item in _filePathList)
            {
                using (var impersonation = new ImpersonatedUser("itadmin", "kmhk.local", "Ed@a*9kj"))
                {
                    if (!File.Exists(item.FilePath))
                    {
                        continue;
                    }

                    double len = new FileInfo(item.FilePath).Length;
                    size += len;
                }
            }

            int order = 0;

            while (size >= 1024 && order + 1 < sizes.Length)
            {
                order++;
                size = size / 1024;
            }

            MessageBox.Show("Size: " + string.Format("{0:0.##} {1}", size, sizes[order]));
        }
Esempio n. 3
0
        private void getSizeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            double size = 0;

            string[] sizes = { "B", "KB", "MB", "GB" };

            foreach (DataGridViewRow row in dgvTotal.SelectedRows)
            {
                string path = row.Cells[3].Value.ToString().Trim();

                using (var impersonation = new ImpersonatedUser("itadmin", "kmhk.local", "Ed@a*9kj"))
                {
                    if (!File.Exists(path))
                    {
                        continue;
                    }

                    double len = new FileInfo(path).Length;
                    size += len;
                }
            }

            int order = 0;

            while (size >= 1024 && order + 1 < sizes.Length)
            {
                order++;
                size = size / 1024;
            }

            MessageBox.Show("Selected items: " + dgvTotal.SelectedRows.Count + "  Size: " + string.Format("{0:0.##} {1}", size, sizes[order]));
        }
Esempio n. 4
0
        public void TestToAzureUser()
        {
            var impersonatorId = Guid.NewGuid();
            var impersonatedId = Guid.NewGuid();
            var username       = "******";
            var user           = new ImpersonatedUser(impersonatorId, impersonatedId, username);

            user.Invoking(x => x.ToAzureUser()).ShouldThrow <NotSupportedException>().WithMessage("This method should not be executed.  A user must exist for it to be impersonated.");
        }
Esempio n. 5
0
        public void TestConstructor()
        {
            var impersonatorId = Guid.NewGuid();
            var impersonatedId = Guid.NewGuid();
            var username       = "******";
            var user           = new ImpersonatedUser(impersonatorId, impersonatedId, username);

            Assert.AreEqual(impersonatorId, user.ImpersonatorUserId);
            Assert.AreEqual(impersonatedId, user.ImpersonatedUserId);
            Assert.AreEqual(username, user.GetUsername());
        }
Esempio n. 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                DataTable table = ImportExcel2007.TranslateToTable(ofd.FileName);

                DataTable errorTable = new DataTable();
                errorTable.Columns.Add("error");

                foreach (DataRow row in table.Rows)
                {
                    //string owner = row.ItemArray[0].ToString().Trim();
                    string path = row.ItemArray[0].ToString().Trim();

                    FileInfo info = new FileInfo(path);

                    try
                    {
                        using (var impersonation = new ImpersonatedUser("itadmin", "kmhk.local", "Cv%^yHfv"))
                        {
                            FileSecurity fs = info.GetAccessControl();
                            AuthorizationRuleCollection rules = fs.GetAccessRules(true, true, typeof(NTAccount));

                            fs.SetAccessRuleProtection(true, false);
                            //if (owner == "Ho Kin Hang(何健恒,Ken)")
                            //fs.AddAccessRule(new FileSystemAccessRule(@"kmas\as1600055", FileSystemRights.FullControl, AccessControlType.Allow));
                            //else
                            fs.AddAccessRule(new FileSystemAccessRule(@"kmas\as1600048", FileSystemRights.FullControl, AccessControlType.Allow));

                            File.SetAccessControl(path, fs);
                        }
                    }
                    catch
                    {
                        errorTable.Rows.Add(path);
                        continue;
                    }
                }

                if (errorTable.Rows.Count > 0)
                {
                    ExportCsvUtil.ExportCsv(errorTable, "", "");
                }
            }
        }
Esempio n. 7
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            DataTable errorTable = new DataTable();

            errorTable.Columns.Add("missed");

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                DataTable table = ImportExcel2007.TranslateToTable(ofd.FileName);

                using (var impersonation = new ImpersonatedUser("itadmin", "kmhk.local", "Ed@a*9kj"))
                {
                    foreach (DataRow row in table.Rows)
                    {
                        string file = row.ItemArray[0].ToString().Trim();
                        string user = row.ItemArray[1].ToString().Trim();
                        string path = row.ItemArray[2].ToString().Trim();

                        if (!File.Exists(path))
                        {
                            errorTable.Rows.Add(path);
                            continue;
                        }

                        string filename  = Path.GetFileName(path);
                        string newPath   = path.Replace(@"\\kdthk-dm1", "");
                        string directory = @"\\kdthk-dm1\dvdstorage$" + newPath.Substring(0, newPath.LastIndexOf(@"\") + 1);

                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }

                        File.Copy(path, directory + filename, true);
                    }
                }

                if (errorTable.Rows.Count > 0)
                {
                    ExportCsvUtil.ExportCsv(errorTable, "", "missed");
                }
            }
        }
Esempio n. 8
0
        private void finishedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgvTotal.SelectedRows)
            {
                string status = row.Cells[4].Value.ToString().Trim();

                if (status != "Processing")
                {
                    continue;
                }

                string requester = row.Cells[1].Value.ToString().Trim();
                string tableName = "TB_" + AdUtil.GetUserIdByUsername(requester, "kmhk.local");
                string path      = row.Cells[3].Value.ToString().Trim();
                string pathCopy  = row.Cells[6].Value.ToString().Trim();

                string newPath = path.Contains("'") ? path.Replace("'", "''") : path;

                using (var impersonation = new ImpersonatedUser("itadmin", "kmhk.local", "Ed@a*9kj"))
                {
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    if (File.Exists(pathCopy))
                    {
                        File.Delete(pathCopy);
                    }
                }

                string query = string.Format("update TB_DISC_REQUEST set d_status = 'Finished', d_finished = 'True', d_finishdatetime = '{1}', d_finishedby = N'{2}' where d_path = N'{0}'", newPath, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), GlobalService.User);
                DataService.GetInstance().ExecuteNonQuery(query);

                string text = string.Format("update " + tableName + " set r_disc = 'True' where r_path = N'{0}'", newPath);
                DataService.GetInstance().ExecuteNonQuery(text);
            }

            MessageBox.Show("Record has been saved.");

            LoadData(txtFilename.Text, txtUser.Text, cbStatus.SelectedItem.ToString());
        }
Esempio n. 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            double size = 0;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string[] sizes = { "B", "KB", "MB", "GB" };

                DataTable table = ImportExcel2007.TranslateToTable(ofd.FileName);

                using (var impersonation = new ImpersonatedUser("itadmin", "kmhk.local", "Ed@a*9kj"))
                {
                    foreach (DataRow row in table.Rows)
                    {
                        //string file = row.ItemArray[0].ToString().Trim();
                        //string user = row.ItemArray[1].ToString().Trim();
                        string path = row.ItemArray[2].ToString().Trim();

                        if (!File.Exists(path))
                        {
                            continue;
                        }

                        double len = new FileInfo(path).Length;
                        size += len;
                    }
                }

                int order = 0;
                while (size >= 1024 && order + 1 < sizes.Length)
                {
                    order++;
                    size = size / 1024;
                }

                MessageBox.Show(string.Format("{0:0.##} {1}", size, sizes[order]));
            }
        }
Esempio n. 10
0
        private void finishedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgvProcessing.SelectedRows)
            {
                string status = row.Cells[4].Value.ToString().Trim();

                if (status != "Processing")
                {
                    continue;
                }

                string user      = row.Cells[2].Value.ToString().Trim();
                string tablename = "TB_" + AdUtil.GetUserIdByUsername(user, "kmhk.local");
                string path      = row.Cells[3].Value.ToString().Trim();
                string pathCopy  = row.Cells[6].Value.ToString().Trim();

                string newPath = path.Contains("'") ? path.Replace("'", "''") : path;

                using (var impersonation = new ImpersonatedUser("itadmin", "kmhk.local", "Ed@a*9kj"))
                {
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    if (File.Exists(pathCopy))
                    {
                        File.Delete(pathCopy);
                    }
                }

                string query = string.Format("update TB_DISC_IDLE set di_status = 'Finished', di_finished = 'Yes', di_finisheddatetime = '{0}', di_finishedby = N'{1}' where di_path = N'{2}'", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), GlobalService.User, newPath);
                DataService.GetInstance().ExecuteNonQuery(query);

                string text = string.Format("update " + tablename + " set r_disc = 'True' where r_path = N'{0}'", newPath);
                DataService.GetInstance().ExecuteNonQuery(text);
            }
        }
Esempio n. 11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            switch (MessageBox.Show("Assign " + _filePathList.Count + " items to Disc with ID: " + txtDiscId.Text + " ? Items will be copied to target directory immediately.", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
            case DialogResult.Yes:

                if (DiscUtil.IsDiscExist(txtDiscId.Text) || DiscUtil.IsDiscExistIdle(txtDiscId.Text))
                {
                    MessageBox.Show("Disc Id " + txtDiscId.Text + " exists.");
                    return;
                }

                foreach (DiscIdleList item in _filePathList)
                {
                    try
                    {
                        using (var impersonation = new ImpersonatedUser("itadmin", "kmhk.local", "Ed@a*9kj"))
                        {
                            string nonMapPath = "";

                            if (item.FilePath.Contains("rps$"))
                            {
                                nonMapPath = item.FilePath.Replace("rps$", @"department\rps");
                            }
                            else if (item.FilePath.Contains("ga$"))
                            {
                                nonMapPath = item.FilePath.Replace("ga$", @"department\ga");
                            }
                            else if (item.FilePath.Contains("cm$"))
                            {
                                nonMapPath = item.FilePath.Replace("cm$", @"department\cm");
                            }
                            else if (item.FilePath.Contains("ipo$"))
                            {
                                nonMapPath = item.FilePath.Replace("ipo$", @"department\ipo purchasing");
                            }
                            else if (item.FilePath.Contains("logistics$"))
                            {
                                nonMapPath = item.FilePath.Replace("logistics$", @"department\logistics");
                            }
                            else if (item.FilePath.Contains("mcc$"))
                            {
                                nonMapPath = item.FilePath.Replace("mcc$", @"department\mcc");
                            }
                            else
                            {
                                nonMapPath = item.FilePath;
                            }

                            if (!File.Exists(nonMapPath))
                            {
                                Debug.WriteLine(nonMapPath + "  is not exist");
                                continue;
                            }
                            string filename = Path.GetFileName(item.FilePath);
                            string newPath  = item.FilePath.Replace(@"\\kdthk-dm1", "");

                            string directory = txtDirectory.Text + @"\" + txtDiscId.Text + newPath.Substring(0, newPath.LastIndexOf(@"\") + 1);

                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }

                            File.Copy(nonMapPath, directory + filename, true);

                            if (filename.Contains("'"))
                            {
                                filename = filename.Replace("'", "''");
                            }
                            string fileDirectory = directory + filename;
                            if (fileDirectory.Contains("'"))
                            {
                                fileDirectory = fileDirectory.Replace("'", "''");
                            }

                            if (item.FilePath.Contains("'"))
                            {
                                item.FilePath = item.FilePath.Replace("'", "''");
                            }

                            string query = string.Format("insert into TB_DISC_IDLE (di_filename, di_path, di_disc, di_status, di_pathcopy, di_lastaccess, di_user) values (N'{0}', N'{1}', N'{2}', N'{3}', N'{4}', '{5}', N'{6}')", filename, item.FilePath, txtDiscId.Text, "Processing", fileDirectory, item.LastAccess, item.User);
                            DataService.GetInstance().ExecuteNonQuery(query);
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
                break;

            case DialogResult.No:
                break;
            }

            DialogResult = DialogResult.OK;
        }