private void tscbProjects_SelectedIndexChanged(object sender, EventArgs e) { if (tscbProjects.ComboBox.Items.Count == 0) { return; } Guid projectID = ((dynamic)tscbProjects.ComboBox.SelectedItem).ProjectID; if (currentDb != null) { currentDb.Dispose(); } currentDb = new SkuDataDbDataContext(); var databaseName = currentDb.Projects.Single(p => p.ID == projectID).DatabaseName; currentProject = currentDb.Projects.Single(p => p.ID == projectID); if (currentDb.Connection.State == ConnectionState.Closed) { currentDb.Connection.Open(); } currentDb.Connection.ChangeDatabase(databaseName); AryaTools.Instance.InstanceData.InitDataContext(projectID, true); LoadPermissions(); }
public void Run(Guid currentUserID = default(Guid)) { _currentDB = new SkuDataDbDataContext(); clbProjects.Tag = lblSelectedProjects; clbGroups.Tag = lblSelectedGroups; clbUsers.Tag = lblSelectedUsers; CurrentUserID = currentUserID; //only admin can create new users if (currentUserID == default(Guid)) { btnUsers.Enabled = true; clbProjects.ContextMenuStrip = cmsProjects; } else { btnUsers.Enabled = false; clbProjects.ContextMenuStrip = null; } LoadUsers(); LoadProjects(); LoadGroups(); LoadUPGs(); }
private void btnSave_Click(object sender, EventArgs e) { bool errors = false; var allTextBoxControls = GetControls(this).Where(p => p.Name.StartsWith("tb")).ToList(); MetaTable projectMeta = currentDb.Mapping.GetTable(typeof(Project)); var dataMembers = projectMeta.RowType.PersistentDataMembers.Where(p => !p.CanBeNull && p.Type == typeof(string)).ToList(); foreach (var requiredMember in dataMembers) { var requiredValue = currentProject.GetPropertyValue(requiredMember.Name); if (requiredValue == null || string.IsNullOrWhiteSpace(requiredValue.ToString())) { MetaDataMember member = requiredMember; epUser.SetError(allTextBoxControls.Single(p => p.Name == "tb" + member.Name), "Invalid Input"); errors = true; } } if (errors) { return; } currentProject.ProjectPreferences = projPreferences; currentDb.SubmitChanges(); if (newProject) { var backupFileName = @"E:\TemporarySpace\" + Guid.NewGuid(); BackupDatabase(backupFileName); RestoreDatabase(currentProject.DatabaseName, backupFileName); using (var targetDb = new SkuDataDbDataContext()) { targetDb.Connection.Open(); targetDb.Connection.ChangeDatabase(currentProject.DatabaseName); //targetDb.Projects.InsertOnSubmit(currentProject.CloneEntity()); targetDb.Attributes.ForEach(att => att.ProjectID = currentProject.ID); targetDb.TaxonomyInfos.ForEach(tax => tax.ProjectID = currentProject.ID); targetDb.Projects.DeleteAllOnSubmit(targetDb.Projects.Where(prj => prj.ID != currentProject.ID)); targetDb.SubmitChanges(); } } else { using (var targetDb = new SkuDataDbDataContext()) { targetDb.Connection.Open(); targetDb.Connection.ChangeDatabase(currentProject.DatabaseName); var targetProject = targetDb.Projects.Single(p => p.ID == currentProject.ID); targetProject.InjectFrom <ProjectInjection>(currentProject); targetDb.SubmitChanges(); } } MessageBox.Show("Project Created.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public FrmGroupManager(Project filteredProject = null) { InitializeComponent(); DisplayStyle.SetDefaultFont(this); Icon = Resources.groupIcon; this.filteredProject = filteredProject; dbContext = new SkuDataDbDataContext(); }
partial void OnCreated() { SkuDataDbDataContext.DefaultTableValues(this); UnitName = "New Unit"; UnitAbbreviation = "n.a."; FromBaseExpression = "b"; ToBaseExpression = "n"; }
public bool InitDataContext(Guid projectID = default(Guid), bool forceInit = false) { if (_dc == null || forceInit) { _dc = new SkuDataDbDataContext(); if (CurrentUser != null) { CurrentUser = _dc.Users.Single(usr => usr.ID.Equals(CurrentUser.ID)); } if (projectID != default(Guid)) { CurrentProject = _dc.Projects.Single(prj => prj.ID == projectID); } else if (CurrentProject != null) { CurrentProject = _dc.Projects.Single(prj => prj.ID.Equals(_currentProject.ID)); } } while (_dc.Connection.State != ConnectionState.Open) { if (_dc.Connection.State == ConnectionState.Closed) { try { _dc.Connection.Open(); } catch (Exception ex) { DialogResult result = MessageBox.Show(ex.Message + @" Do you want to try again?", @"Database connection lost", MessageBoxButtons.YesNo); if (result == DialogResult.No) { Application.Exit(); return(false); } } } while (_dc.Connection.State == ConnectionState.Connecting) { Thread.Sleep(100); } } return(true); }
private void btnCreateUser_Click(object sender, EventArgs e) { epNewUser.Clear(); var errors = false; if (!ValidateEmailAddress()) { epNewUser.SetError(tbEmailAddress, "Valid Email Address required"); errors = true; } if (string.IsNullOrWhiteSpace(tbFullName.Text)) { epNewUser.SetError(tbFullName, "Valid Full Name required"); errors = true; } if (errors) { return; } using (var db = new SkuDataDbDataContext()) { var ssoID = db.Users.Max(p => p.SingleSignOnId) + 1; var newUser = new User { ID = Guid.NewGuid(), EmailAddress = tbEmailAddress.Text.Trim(), FullName = tbFullName.Text.Trim(), SingleSignOnId = ssoID, CreatedOn = DateTime.Now, Active = true }; db.Users.InsertOnSubmit(newUser); db.SubmitChanges(); MessageBox.Show(@"New User Created", @"New User", MessageBoxButtons.OK, MessageBoxIcon.Information); btnClear.PerformClick(); } }
private void btnDeleteUPG_Click(object sender, EventArgs e) { List <Guid> deletedUPGIDs = (from row in dgvUserProjectGroups.Rows.Cast <DataGridViewRow>().Where( p => p.Cells[0].Value != null) let deleteCheckboxCell = row.Cells[1] as DataGridViewCheckBoxCell where deleteCheckboxCell != null && deleteCheckboxCell.Value != null && (bool)deleteCheckboxCell.Value select(Guid) row.Cells[0].Value).ToList(); _currentDB.UserProjects.DeleteAllOnSubmit( _currentDB.UserProjects.Where(p => deletedUPGIDs.Contains(p.ID))); var dbList = _currentDB.UserProjects.Where(p => deletedUPGIDs.Contains(p.ID)).Select( p => p.Project.DatabaseName).Distinct().ToList(); foreach (var db in dbList) { using (var admindb = new SkuDataDbDataContext()) { admindb.Connection.Open(); admindb.Connection.ChangeDatabase(db); admindb.UserProjects.DeleteAllOnSubmit( admindb.UserProjects.Where(p => deletedUPGIDs.Contains(p.ID))); admindb.SubmitChanges(); } } //AryaTools.Instance.SaveChangesIfNecessary(false, true); SaveCurrentDb(); LoadUPGs(); ToggleDeleteUPGButton(); }
partial void OnCreated() { SkuDataDbDataContext.DefaultTableValues(this); }
private void btnAddUPG_Click(object sender, EventArgs e) { List <Guid> selectedUsers = (from object currentItem in clbUsers.CheckedItems select currentItem.GetType().GetProperty("UserID").GetValue(currentItem, null)). OfType <Guid>().ToList(); List <Guid> selectedGroups = (from object currentItem in clbGroups.CheckedItems select currentItem.GetType().GetProperty("GroupID").GetValue(currentItem, null)) .OfType <Guid>().ToList(); List <Guid> selectedProjects = (from object currentItem in clbProjects.CheckedItems select currentItem.GetType().GetProperty("ProjectID").GetValue(currentItem, null)) .OfType <Guid>().ToList(); var userLists = _currentDB.Users.Where(p => selectedUsers.Contains(p.ID)).ToList(); var groupList = _currentDB.Groups.Where(p => selectedGroups.Contains(p.ID)).ToList(); var dbLists = _currentDB.Projects.Where(p => selectedProjects.Contains(p.ID)).Select(d => d.DatabaseName).Distinct().ToList(); foreach (var db in dbLists) { using (var admindb = new SkuDataDbDataContext()) { admindb.Connection.Open(); admindb.Connection.ChangeDatabase(db); var missingUsers = selectedUsers.Except(admindb.Users.Select(p => p.ID)); foreach (var usr in missingUsers) { var currentMissingUser = usr; admindb.Users.InsertOnSubmit(userLists.Single(p => p.ID == currentMissingUser).CloneEntity()); } var missingGroups = selectedGroups.Except(admindb.Groups.Select(p => p.ID)); foreach (var grp in missingGroups) { var currentMissingGrp = grp; admindb.Groups.InsertOnSubmit(groupList.Single(p => p.ID == currentMissingGrp).CloneEntity()); } admindb.SubmitChanges(); } } var newUPGs = selectedUsers.SelectMany( selectedUserID => selectedProjects.SelectMany(selectedProjectID => (from selectedGroupID in selectedGroups let userID = selectedUserID let projectID = selectedProjectID let groupID = selectedGroupID let newUPG = _currentDB.UserProjects.SingleOrDefault(p => p.UserID == userID && p.ProjectID == projectID && p.GroupID == groupID) where newUPG == null select new UserProject { ID = Guid.NewGuid(), ProjectID = selectedProjectID, UserID = selectedUserID, GroupID = selectedGroupID }))).ToList(); foreach (UserProject newUPG in newUPGs) { _currentDB.UserProjects.InsertOnSubmit(newUPG); } foreach (var db in dbLists) { using (var admindb = new SkuDataDbDataContext()) { admindb.Connection.Open(); admindb.Connection.ChangeDatabase(db); var currentDbProjects = admindb.Projects.Select(p => p.ID).ToList(); foreach (var newUPG in newUPGs.Where(p => currentDbProjects.Contains(p.ProjectID))) { var currentNewUPG = newUPG; admindb.UserProjects.InsertOnSubmit(currentNewUPG.CloneEntity()); } admindb.SubmitChanges(); } } //AryaTools.Instance.SaveChangesIfNecessary(false, true); SaveCurrentDb(); LoadUPGs(); }
public override void Run() { State = WorkerState.Working; _parsedSkuExclusions = ParseSkuInclusionAndExclusions(SkuExclusions); _parsedSkuInclusions = ParseSkuInclusionAndExclusions(SkuInclusions); //parsedSkuValueInclusions = ParseSkuValueInclusions(SkuValueInclusions); _taxonomyAttributesCache = new Dictionary <Guid, List <Tuple <Attribute, decimal, decimal> > >(); _baseAttributeNames = new Dictionary <string, string>(); _delimiter = FieldDelimiter.GetValue().ToString(); //Create new context _currentDb = new SkuDataDbDataContext(); var dlo = new DataLoadOptions(); _projectField1Name = AryaTools.Instance.InstanceData.CurrentProject.EntityField1Name ?? string.Empty; dlo.LoadWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas); dlo.LoadWith <EntityInfo>(entityInfo => entityInfo.EntityDatas); dlo.LoadWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas); //dlo.AssociateWith<TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas.Where(p => p.Active)); //dlo.AssociateWith<EntityInfo>(entityInfo => entityInfo.EntityDatas.Where(p => p.Active)); dlo.AssociateWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas.Where(p => p.Active)); //dlo.AssociateWith<TaxonomyInfo>(taxonomyInfo => taxonomyInfo.SkuInfos.Where(p => p.Active)); _currentDb.LoadOptions = dlo; _currentDb.CommandTimeout = 2000; _currentDb.Connection.Open(); _currentDb.Connection.ChangeDatabase(AryaTools.Instance.InstanceData.Dc.Connection.Database); InitGlobals(GlobalAttributes); StatusMessage = "Init"; var fi = new FileInfo(ExportFileName); var baseFileName = fi.FullName.Replace(fi.Extension, string.Empty); _taxonomyFile = new StreamWriter(baseFileName + "_Classification.txt", false, Encoding.UTF8); _taxonomyFile.WriteLine("ItemId{0}New Taxonomy{0}Node Type{0}Old Taxonomy", _delimiter); _attributeDataFile = new StreamWriter(baseFileName + "_AttributeData.txt", false, Encoding.UTF8); if (GenerateFileWithBlankValues) { _blankValuesAttributeDataFile = new StreamWriter(baseFileName + "_AttributeBlanks.txt", false, Encoding.UTF8); } _attributeDataFile.Write("ItemId{0}Taxonomy{0}Node Type", _delimiter); if (GenerateFileWithBlankValues) { _blankValuesAttributeDataFile.Write("ItemId{0}Taxonomy{0}Node Type", _delimiter); } foreach (var attribute in _globalAttributeHeaders) { string attributeHeader = null; var parts = attribute.Split(':'); var noOfHeaders = 0; if (parts.Count() > 1) { Int32.TryParse(parts[1].Trim(), out noOfHeaders); } if (parts.Count() == 2 && noOfHeaders > 0) { for (var i = 0; i < noOfHeaders; i++) { if (attributeHeader == null) { attributeHeader += parts[0].Trim() + (i + 1); } else { attributeHeader += "\t" + parts[0].Trim() + (i + 1); } } } else { attributeHeader = attribute; } _attributeDataFile.Write("{0}{1}", _delimiter, attributeHeader); if (GenerateFileWithBlankValues) { _blankValuesAttributeDataFile.Write("{0}{1}", _delimiter, attributeHeader); } } if (ExportRanks) { _attributeDataFile.Write("{0}Rank 1", _delimiter); if (GenerateFileWithBlankValues) { _blankValuesAttributeDataFile.Write("{0}Rank 1", _delimiter); } } _attributeDataFile.Write("{0}Att 1", _delimiter); if (GenerateFileWithBlankValues) { _blankValuesAttributeDataFile.Write("{0}Att 1", _delimiter); } if (ExportNewValueColumn) { _attributeDataFile.Write("{0}New Value 1", _delimiter); if (GenerateFileWithBlankValues) { _blankValuesAttributeDataFile.Write("{0}New Value 1", _delimiter); } } _attributeDataFile.Write("{0}Val 1", _delimiter); if (IncludeUoM) { _attributeDataFile.Write("{0}Uom 1", _delimiter); } if (IncludeField1) { _attributeDataFile.Write("{0}Field 1 1", _delimiter); } if (IncludeField2) { _attributeDataFile.Write("{0}Field 2 1", _delimiter); } if (IncludeField3) { _attributeDataFile.Write("{0}Field 3 1", _delimiter); } if (IncludeField4) { _attributeDataFile.Write("{0}Field 4 1", _delimiter); } if (IncludeField5) { _attributeDataFile.Write("{0}Field 5 1", _delimiter); } _attributeDataFile.WriteLine("{0}[...]", _delimiter); if (GenerateFileWithBlankValues) { _blankValuesAttributeDataFile.Write("{0}Val 1", _delimiter); if (IncludeUoM) { _blankValuesAttributeDataFile.Write("{0}Uom 1", _delimiter); } if (IncludeField1) { _blankValuesAttributeDataFile.Write("{0}Field 1 1", _delimiter); } if (IncludeField2) { _blankValuesAttributeDataFile.Write("{0}Field 2 1", _delimiter); } if (IncludeField3) { _blankValuesAttributeDataFile.Write("{0}Field 3 1", _delimiter); } if (IncludeField4) { _blankValuesAttributeDataFile.Write("{0}Field 4 1", _delimiter); } if (IncludeField5) { _blankValuesAttributeDataFile.Write("{0}Field 5 1", _delimiter); } _blankValuesAttributeDataFile.WriteLine("{0}[...]", _delimiter); } var exportTaxonomyIds = Taxonomies.Cast <ExtendedTaxonomyInfo>().Select(p => p.Taxonomy.ID).Distinct().ToList(); var exportTaxonomies = _currentDb.TaxonomyInfos.Where(p => exportTaxonomyIds.Contains(p.ID)).ToList(); var allExportTaxonomies = exportTaxonomies.SelectMany(p => p.AllChildren2).Union(exportTaxonomies).Distinct().ToList(); CurrentProgress = 0; MaximumProgress = allExportTaxonomies.Count; foreach (var exportChildTaxonomy in allExportTaxonomies) { WriteTaxonomyToFile(exportChildTaxonomy); CurrentProgress++; } _taxonomyFile.Close(); _attributeDataFile.Close(); if (GenerateFileWithBlankValues) { _blankValuesAttributeDataFile.Close(); } StatusMessage = "Done!"; State = WorkerState.Ready; }
public override void Run() { State = WorkerState.Working; _parsedSkuExclusions = ParseSkuInclusionAndExclusions(SkuExclusions); _parsedSkuInclusions = ParseSkuInclusionAndExclusions(SkuInclusions); _delimiter = FieldDelimiter.GetValue().ToString(); //Create new context _currentDb = new SkuDataDbDataContext(); var dlo = new DataLoadOptions(); dlo.LoadWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas); dlo.LoadWith <EntityInfo>(entityInfo => entityInfo.EntityDatas); dlo.LoadWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas); //dlo.AssociateWith<TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas.Where(p => p.Active)); dlo.AssociateWith <EntityInfo>(entityInfo => entityInfo.EntityDatas.Where(p => p.Active)); dlo.AssociateWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas.Where(p => p.Active)); //dlo.AssociateWith<TaxonomyInfo>(taxonomyInfo => taxonomyInfo.SkuInfos.Where(p => p.Active)); _currentDb.LoadOptions = dlo; _currentDb.CommandTimeout = 2000; _currentDb.Connection.Open(); _currentDb.Connection.ChangeDatabase(AryaTools.Instance.InstanceData.Dc.Connection.Database); _separator = AryaTools.Instance.InstanceData.CurrentProject.ListSeparator; StatusMessage = "Init"; var fi = new FileInfo(ExportFileName); _baseFileName = fi.FullName.Replace(fi.Extension, string.Empty); //_taxonomyFile = new StreamWriter(_baseFileName + "_Classification.txt", false, Encoding.UTF8); //_taxonomyFile.WriteLine("ItemId{0}New Taxonomy{0}Node Type{0}Old Taxonomy", _delimiter); var exportTaxonomyIds = Taxonomies.Cast <ExtendedTaxonomyInfo>().Select(p => p.Taxonomy.ID).Distinct().ToList(); var exportTaxonomies = _currentDb.TaxonomyInfos.Where(p => exportTaxonomyIds.Contains(p.ID)).ToList(); var allExportTaxonomies = exportTaxonomies.SelectMany(p => p.AllChildren2).Union(exportTaxonomies).Distinct().ToList(); var exportGroups = allExportTaxonomies.GroupBy(GetTaxPrefix).ToList(); CurrentProgress = 0; MaximumProgress = exportGroups.Count(); foreach (var grp in exportGroups) { WriteTaxonomyToFile(grp.Select(g => g), grp.Key); CurrentProgress++; } //_taxonomyFile.Close(); StatusMessage = "Done!"; State = WorkerState.Ready; }
public void Run(Guid currentUserID, bool isAdmin, Guid currentProjectIDValue = default(Guid)) { if (currentDb != null) { currentDb.Dispose(); } currentDb = new SkuDataDbDataContext(); Version currentVersion = Program.GetCurrrentCodeVersion(); var allUserProjects = !isAdmin ? currentDb.ExecuteQuery <Project>( @"SELECT * FROM Project WHERE ID IN ( SELECT DISTINCT p.ID FROM UserProject up INNER JOIN Project p ON up.ProjectID = p.ID WHERE up.UserID = {0} and up.GroupID = {1} AND EXISTS ( SELECT database_id FROM sys.databases sd WHERE sd.Name = p.DatabaseName and p.AryaCodeBaseVersion ={2} ) ) ", currentUserID, Group.PermissionsManagerGroup, currentVersion.Major + "." + currentVersion.Minor).ToList().Select( p => new { p.ProjectDescription, ProjectID = p.ID }).Distinct().ToList() : currentDb.ExecuteQuery <Project>(@"SELECT * FROM Project p INNER JOIN sys.databases sd ON sd.Name = p.DatabaseName WHERE p.AryaCodeBaseVersion={0}", currentVersion.Major + "." + currentVersion.Minor).ToList().Select( p => new { p.ProjectDescription, ProjectID = p.ID }).Distinct().ToList(); if (allUserProjects.Count == 0) { MessageBox.Show("You are not Permission Manager in any project!!"); return; } tscbProjects.SelectedIndexChanged -= tscbProjects_SelectedIndexChanged; tscbProjects.ComboBox.DataSource = allUserProjects; tscbProjects.ComboBox.DisplayMember = "ProjectDescription"; tscbProjects.ComboBox.ValueMember = "ProjectID"; //resizes the combobox to show the longest string using (Graphics graphics = CreateGraphics()) { int maxWidth = 0; foreach (object obj in tscbProjects.ComboBox.Items) { var currentString = ((dynamic)obj).ProjectDescription; var area = graphics.MeasureString(currentString, tscbProjects.ComboBox.Font); maxWidth = Math.Max((int)area.Width, maxWidth); } tscbProjects.ComboBox.Width = maxWidth + 15; if (maxWidth + 50 > tlpPermissionsManager.ColumnStyles[0].Width) { tlpPermissionsManager.ColumnStyles[0].Width = maxWidth + 70; } } tscbProjects.SelectedIndex = currentProjectIDValue != default(Guid) ? allUserProjects.IndexOf( allUserProjects.Single(p => p.ProjectID == currentProjectIDValue)) :0; // if (tscbProjects.SelectedIndex == 0) // { // currentDb.ExecuteQuery<Project>( // @"SELECT * // FROM Project // WHERE ID IN ( // SELECT DISTINCT p.ID // FROM UserProject up // INNER JOIN Project p ON up.ProjectID = p.ID // WHERE up.UserID = {0} // AND EXISTS ( // SELECT database_id FROM sys.databases sd WHERE sd.Name = p.DatabaseName // ) // ) // ", // currentUserID) // } tscbProjects.SelectedIndexChanged += tscbProjects_SelectedIndexChanged; tscbProjects_SelectedIndexChanged(tscbProjects, EventArgs.Empty); LoadPermissions(); }
public override void Run() { State = WorkerState.Working; _parsedSkuExclusions = ParseSkuInclusionAndExclusions(SkuExclusions); _parsedSkuInclusions = ParseSkuInclusionAndExclusions(SkuInclusions); _delimiter = FieldDelimiter.GetValue().ToString(); _currentDb = new SkuDataDbDataContext(); var dlo = new DataLoadOptions(); dlo.LoadWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas); dlo.LoadWith <EntityInfo>(entityInfo => entityInfo.EntityDatas); dlo.LoadWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas); dlo.AssociateWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas.Where(p => p.Active)); dlo.AssociateWith <EntityInfo>(entityInfo => entityInfo.EntityDatas.Where(p => p.Active || p.BeforeEntity)); dlo.AssociateWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas.Where(p => p.Active)); dlo.AssociateWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.SkuInfos.Where(p => p.Active)); _currentDb.LoadOptions = dlo; _currentDb.CommandTimeout = 2000; _currentDb.Connection.Open(); _currentDb.Connection.ChangeDatabase(AryaTools.Instance.InstanceData.Dc.Connection.Database); var fi = new FileInfo(ExportFileName); var baseFileName = fi.FullName.Replace(fi.Extension, string.Empty); _attributeFile = new StreamWriter(baseFileName + "_attributes.txt", false, Encoding.UTF8); _valueFile = new StreamWriter(baseFileName + "_values.txt", false, Encoding.UTF8); _skuFile = new StreamWriter(baseFileName + "_skus.txt", false, Encoding.UTF8); StatusMessage = "Init"; var allExportTaxonomyIds = Taxonomies.Cast <ExtendedTaxonomyInfo>().Select(p => p.Taxonomy.ID).Distinct().ToList(); var exportTaxonomies = _currentDb.TaxonomyInfos.Where(p => allExportTaxonomyIds.Contains(p.ID)).ToList(); var allChildren = exportTaxonomies.SelectMany(p => p.AllChildren).Distinct().ToList(); var allLeafChildren = exportTaxonomies.SelectMany(p => p.AllLeafChildren).Distinct().ToList(); var maxDepth = 0; if (allChildren.Count == 0 && allLeafChildren.Count != 0) { maxDepth = allLeafChildren.Select( child => child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length) .Max(); } else if (allLeafChildren.Count == 0 && allChildren.Count != 0) { maxDepth = allChildren.Select( child => child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length) .Max(); } else if (allLeafChildren.Count != 0 && allChildren.Count != 0) { if (allLeafChildren.Count >= allChildren.Count) { maxDepth = allLeafChildren.Select( child => child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length).Max(); } else { maxDepth = allChildren.Select( child => child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length).Max(); } } else { StatusMessage = "There was no data to export."; MaximumProgress = 1; CurrentProgress = 1; State = WorkerState.Ready; } if (IgnoreT1Taxonomy) { maxDepth--; } for (var i = 1; i <= maxDepth; i++) { _attributeFile.Write("T" + i + "\t"); _valueFile.Write("T" + i + "\t"); _skuFile.Write("T" + i + "\t"); } _attributeFile.WriteLine( "Attribute{0}Node Sku Count{0}Attr. Sku Count{0}Fill Rate{0}Navigation Order{0}Display Order{0}Global", _delimiter); _valueFile.WriteLine( "Attribute{0}Value{0}Uom{0}Node Sku Count{0}Attr. Value Sku Count{0}Value Fill Rate{0}Attr. Fill Rate{0}Navigation Order{0}Display Order{0}Global", _delimiter); _skuFile.WriteLine( "Item Id{0}Node Attr. Count{0}Node Nav. Attr. Count{0}Node Disp. Attr. Count{0}Sku Attr. Count{0}Sku Nav. Attr. Count{0}Sku Disp. Attr. Count{0}Sku Attr. Fill Rate{0}Sku Nav. Attr. Fill Rate{0}Node Disp. Attr. Fill Rate", _delimiter); CurrentProgress = 0; if (allChildren.Count >= allLeafChildren.Count) { MaximumProgress = allChildren.Count; foreach (var child in allChildren) { WriteMetricsToFile(child, maxDepth); CurrentProgress++; } } else if (allChildren.Count < allLeafChildren.Count) { MaximumProgress = allLeafChildren.Count; foreach (var child in allLeafChildren) { WriteMetricsToFile(child, maxDepth); CurrentProgress++; } } _attributeFile.Close(); _valueFile.Close(); _skuFile.Close(); StatusMessage = "Done!"; State = WorkerState.Ready; }
private void PrepareData() { //Load all the projects for the User. currentDb = new SkuDataDbDataContext(); if (currentProjectID != Guid.Empty) { currentProject = currentDb.Projects.Single(p => p.ID == currentProjectID); Text = Text + " : " + currentProject.ProjectDescription; projPreferences = currentProject.ProjectPreferences; } else { //ID and other fields will be set in the defaultValues method. currentProject = new Project(); currentDb.Projects.InsertOnSubmit(currentProject); Text = Text + " : <New Project>"; newProject = true; currentProjectID = currentProject.ID; projPreferences = new ProjectPreferences { ListSeparator = "; ", ReturnSeparator = "|" }; } tbProjectName.Text = currentProject.ProjectName; //can edit Project name only for new projects tbProjectName.Enabled = newProject; tbDatabaseName.Text = currentProject.DatabaseName; //can edit database name only for new projects tbDatabaseName.Enabled = newProject; tbListSeparator.Text = projPreferences.ListSeparator; tbReturnSeparator.Text = projPreferences.ReturnSeparator; tbClientDescription.Text = currentProject.ClientDescription; tbSetName.Text = currentProject.SetName; //Field1 tbEntityField1Name.Text = currentProject.EntityField1Name; cbEntityField1ReadOnly.Checked = currentProject.EntityField1Readonly; //Field2 tbEntityField2Name.Text = currentProject.EntityField2Name; cbEntityField2ReadOnly.Checked = currentProject.EntityField2Readonly; //Field3 tbEntityField3Name.Text = currentProject.EntityField3Name; cbEntityField3ReadOnly.Checked = currentProject.EntityField3Readonly; //Field4 tbEntityField4Name.Text = currentProject.EntityField4Name; cbEntityField4ReadOnly.Checked = currentProject.EntityField4Readonly; //Field5 tbEntityField5Name.Text = currentProject.EntityField5Name; cbEntityField5ReadOnly.Checked = currentProject.EntityField5Readonly; cbEntityField5IsStatus.Checked = currentProject.EntityField5IsStatus; //Image URL tbProductSearchString.Text = currentProject.ImageUrlString; tbSchemaFillRateFilters.Text = currentProject.SchemaFillRateFilters; //Hookup all the events var allTextBoxControls = GetControls(this).Where(p => p.Name.StartsWith("tb")).ToList(); foreach (var textBoxControl in allTextBoxControls) { var method = GetType().GetMethod("tbAllFields_TextChanged", BindingFlags.NonPublic | BindingFlags.Instance); var type = typeof(EventHandler); var handler = Delegate.CreateDelegate(type, this, method); var evt = textBoxControl.GetType().GetEvent("TextChanged"); evt.AddEventHandler(textBoxControl, handler); } var allCheckBoxControls = GetControls(this).Where(p => p.Name.StartsWith("cb")).ToList(); foreach (var checkBoxControl in allCheckBoxControls) { var method = GetType().GetMethod("cbAllFields_CheckedChanged", BindingFlags.NonPublic | BindingFlags.Instance); var type = typeof(EventHandler); var handler = Delegate.CreateDelegate(type, this, method); var evt = checkBoxControl.GetType().GetEvent("CheckedChanged"); evt.AddEventHandler(checkBoxControl, handler); } }
public override void Run() { State = WorkerState.Working; parsedSkuExclusions = ParseSkuInclusionAndExclusions(SkuExclusions); parsedSkuInclusions = ParseSkuInclusionAndExclusions(SkuInclusions); //parsedSkuValueInclusions = ParseSkuValueInclusions(SkuValueInclusions); taxonomyAttributesCache = new Dictionary <Guid, List <KeyValuePair <Attribute, SchemaData> > >(); baseAttributeNames = new Dictionary <string, string>(); delimiter = FieldDelimiter.GetValue().ToString(); //Create new context currentDb = new SkuDataDbDataContext(); var dlo = new DataLoadOptions(); projectField1Name = AryaTools.Instance.InstanceData.CurrentProject.EntityField1Name ?? string.Empty; dlo.LoadWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas); dlo.LoadWith <EntityInfo>(entityInfo => entityInfo.EntityDatas); dlo.LoadWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas); dlo.AssociateWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas.Where(p => p.Active)); dlo.AssociateWith <EntityInfo>(entityInfo => entityInfo.EntityDatas.Where(p => p.Active)); dlo.AssociateWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas.Where(p => p.Active)); dlo.AssociateWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.SkuInfos.Where(p => p.Active)); currentDb.LoadOptions = dlo; currentDb.CommandTimeout = 2000; currentDb.Connection.Open(); currentDb.Connection.ChangeDatabase(AryaTools.Instance.InstanceData.Dc.Connection.Database); InitGlobals(GlobalAttributes.ToList()); StatusMessage = "Init"; var fi = new FileInfo(ExportFileName); var baseFileName = fi.FullName.Replace(fi.Extension, string.Empty); attributeDataFile = new StreamWriter(baseFileName + "_AttributeData.txt", false, Encoding.UTF8); attributeDataFile.Write("ItemId{0}Taxonomy{0}Node Type", delimiter); foreach (var attribute in globalAttributeHeaders) { string attributeHeader = null; var parts = attribute.Split(':'); var noOfHeaders = 0; if (parts.Count() > 1) { Int32.TryParse(parts[1].Trim(), out noOfHeaders); } if (parts.Count() == 2 && noOfHeaders > 0) { for (var i = 0; i < noOfHeaders; i++) { if (attributeHeader == null) { attributeHeader += parts[0].Trim() + (i + 1); } else { attributeHeader += "\t" + parts[0].Trim() + (i + 1); } } } else { attributeHeader = attribute; } attributeDataFile.Write("{0}{1}", delimiter, attributeHeader); } attributeDataFile.WriteLine("{0}Rank 1{0}Att 1{0}Val 1{0}Uom 1{0}[...]", delimiter); CurrentProgress = 0; if (SkuCollection != null && SkuCollection.Any()) { var taxonomies = (SkuCollection.Split(2000) .SelectMany(skus => currentDb.Skus.Where(s => skus.Contains(s.ItemID))) .GroupBy(s => s.Taxonomy)).ToList(); MaximumProgress = taxonomies.Count; foreach (var st in taxonomies) { WriteSkusToFile(st.Key, st.ToList()); CurrentProgress++; } } else { var allExportTaxonomyIds = Taxonomies.Cast <ExtendedTaxonomyInfo>().Select(p => p.Taxonomy.ID).Distinct().ToList(); var exportTaxonomies = currentDb.TaxonomyInfos.Where(p => allExportTaxonomyIds.Contains(p.ID)).ToList(); var allExportChildTaxonomies = exportTaxonomies.SelectMany(p => p.AllChildren2).Distinct().ToList(); MaximumProgress = allExportChildTaxonomies.Count; foreach (var exportChildTaxonomy in allExportChildTaxonomies) { WriteTaxonomyToFile(exportChildTaxonomy); CurrentProgress++; } } attributeDataFile.Close(); StatusMessage = "Done!"; State = WorkerState.Ready; }
public override void Run() { var currentDb = new SkuDataDbDataContext(); currentDb.Connection.Open(); currentDb.Connection.ChangeDatabase(AryaTools.Instance.InstanceData.Dc.Connection.Database); var allExportTaxonomyIds = Taxonomies.Cast <ExtendedTaxonomyInfo>().Select(p => p.Taxonomy.ID).Distinct().ToList(); var exportTaxonomies = currentDb.TaxonomyInfos.Where(p => allExportTaxonomyIds.Contains(p.ID)).ToList(); // var baseFileName = ExportFileName; var fi = new FileInfo(ExportFileName); var baseFileName = fi.FullName.Replace(fi.Extension, string.Empty); // initialize base file _schemaFile = new StreamWriter(baseFileName + ".txt", false, Encoding.UTF8); // initialize LOV file _lovFile = new StreamWriter(baseFileName + "_Lov.txt", false, Encoding.UTF8); // initialize Taxonomy file _taxFile = new StreamWriter(baseFileName + "_Tax.txt", false, Encoding.UTF8); StatusMessage = "Init"; State = WorkerState.Working; AryaTools.Instance.AllFillRates.UseBackgroundWorker = false; _delimiter = EnumExtensions.GetValue(FieldDelimiter).ToString(); _possibleMissingInSchemaAttributes = new List <string>(); Init(); var maxDepth = 0; var allChildren = exportTaxonomies.SelectMany(p => p.AllChildren).Distinct().ToList(); var allLeafChildren = exportTaxonomies.SelectMany(p => p.AllLeafChildren).Distinct().ToList(); if (allChildren.Count == 0 && allLeafChildren.Count != 0) { maxDepth = allLeafChildren.Select( child => child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length) .Max(); } else if (allLeafChildren.Count == 0 && allChildren.Count != 0) { maxDepth = allChildren.Select( child => child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length) .Max(); } else if (allLeafChildren.Count != 0 && allChildren.Count != 0) { if (allLeafChildren.Count >= allChildren.Count) { maxDepth = allLeafChildren.Select( child => child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length) .Max(); } else { maxDepth = allChildren.Select( child => child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length) .Max(); } } else { StatusMessage = "There was no data to export."; MaximumProgress = 1; CurrentProgress = 1; State = WorkerState.Ready; } if (IgnoreT1Taxonomy && maxDepth > 1) { maxDepth--; } _taxFile.Write("Taxonomy{0}", _delimiter); _schemaFile.Write("Taxonomy{0}", _delimiter); for (var i = 1; i <= maxDepth; i++) { _schemaFile.Write("T" + i + "\t"); _lovFile.Write("T" + i + "\t"); _taxFile.Write("T" + i + "\t"); } // _schemaFile.Write("Taxonomy{0}T1{0}T2{0}T3{0}T4{0}T5{0}T6{0}T7{0}T8{0}NodeType{0}Attribute", _delimiter); _schemaFile.Write("NodeType{0}Attribute", _delimiter); foreach (var schematus in _allSchemati) { _schemaFile.Write(_delimiter + schematus); } _schemaFile.WriteLine(); // _lovFile.Write("T1{0}T2{0}T3{0}T4{0}T5{0}T6{0}T7{0}T8{0}NodeType{0}AttributeName{0}NavigationOrder{0}DisplayOrder{0}Value",_delimiter); _lovFile.Write("NodeType{0}AttributeName{0}NavigationOrder{0}DisplayOrder{0}Value", _delimiter); if (ExportEnrichments) { _lovFile.Write("{0}EnrichmentImage{0}EnrichmentCopy", _delimiter); } _lovFile.WriteLine(); foreach (var metaAttribute in _taxMetaAttributes) { _taxFile.Write(_delimiter + metaAttribute.AttributeName); } _taxFile.WriteLine(); //if (ExportEnrichments) // _taxFile.Write("{0}EnrichmentImage{0}EnrichmentCopy", _delimiter); //_taxFile.WriteLine(); // create download folder, if requested if (ExportEnrichments && DownloadAssets) { _downloadDir = new DirectoryInfo(baseFileName + "_Assets"); _downloadDir.Create(); } var allTaxonomies = Taxonomies.Cast <ExtendedTaxonomyInfo>().ToList(); MaximumProgress = allTaxonomies.Sum(p => TaxonomyInfo.GetNodeCount(p.Taxonomy)) + 1; CurrentProgress = 0; // MaximumProgress = allChildren.Count; var mscFillRateHelper = new MSCFillRateHelper(); _fillRates = new List <Tuple <string, Guid, Guid, decimal> >(5000); if (ExportFillRates) { foreach (var exportTaxonomyInfo in allTaxonomies) { mscFillRateHelper.GetFillRates(exportTaxonomyInfo.Taxonomy.ID, AryaTools.Instance.InstanceData.CurrentProject.ProjectName); } } foreach (var exportTaxonomyInfo in allTaxonomies) { WriteTaxonomyToFile(exportTaxonomyInfo.Taxonomy, maxDepth); } CurrentProgress++; _schemaFile.Close(); _lovFile.Close(); _lovFile.Dispose(); _taxFile.Close(); var exceptionFileName = baseFileName + "_Exceptions.txt"; File.WriteAllLines(exceptionFileName, _possibleMissingInSchemaAttributes, Encoding.UTF8); AryaTools.Instance.AllFillRates.UseBackgroundWorker = true; StatusMessage = "Done!"; State = WorkerState.Ready; }