void NormalizeAppUpdates(AppUpdate update) { KeyIndexer ndxer = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.APP_UPDATE); var seq = from AppUpdate up in ndxer.Source.Enumerate() where up.AppArchitecture == update.AppArchitecture && up.Version.CompareTo(update.Version) > 0 select up; if (seq.Any()) { update.DeployTime = AppUpdate.NEVER; } else { seq = from AppUpdate up in ndxer.Source.Enumerate() where up.AppArchitecture == update.AppArchitecture && up.Version.CompareTo(update.Version) <= 0 && up.DeployTime == AppUpdate.NOT_YET select up; foreach (AppUpdate up in seq.ToArray()) { var datum = new AppUpdate(up.ID, up.Version, up.AppArchitecture, up.CreationTime); datum.DeployTime = AppUpdate.NEVER; int ndx = ndxer.IndexOf(up.ID); ndxer.Source.Replace(ndx, datum); } } }
public SpotValueForm(IDatumProvider srcValues, IDatum datum) { Assert(datum is SpotValue); Assert(srcValues != null); InitializeComponent(); m_nudPrice.Maximum = decimal.MaxValue; m_ndxerValues = new KeyIndexer(srcValues); m_spotValue = datum as SpotValue; m_nudPrice.DecimalPlaces = AppContext.Settings.AppSettings.PriceDecimalPlaces; ConnectAsync(); m_nudPrice.Value = (decimal)m_spotValue.Price; m_dtpSpotTime.Value = m_spotValue.SpotTime; m_nudPrice.TextChanged += delegate { UpdateUI(); }; m_tsbReload.Click += delegate { m_nudPrice.Value = (decimal)m_spotValue.Price + 1; //si m_nudPrice.Value == m_spotValue.Price l'affichage m_nudPrice.Value = (decimal)m_spotValue.Price; // n'est pas mis a jour m_dtpSpotTime.Value = m_spotValue.SpotTime; }; m_tsbSave.Click += delegate { Save(); }; m_ndxerValues.DatumDeleted += FreezeDialog; m_ndxerValues.DatumReplaced += FreezeDialog; }
public CountryForm(IDatumProvider countryProvider, IDatum datum = null) { Assert(countryProvider != null); Assert(datum == null || datum is Country); InitializeComponent(); m_nudInternalCode.Maximum = CountryRow.MAX_INTERNAL_CODE; m_ndxerCountries = new KeyIndexer(countryProvider); if (datum != null) { m_datum = datum as Country; m_ndxerCountries.DatumDeleted += Countries_DatumChanged; m_ndxerCountries.DatumReplaced += Countries_DatumChanged; m_tsbReload.Click += delegate { ShowDatum(); }; } //handlers EventHandler txtChanged = delegate { UpdateUI(); }; m_tbName.TextChanged += txtChanged; m_nudInternalCode.TextChanged += txtChanged; m_tsbSave.Click += delegate { SaveDatum(); }; }
public ClientsManager() { m_netTimer = new Timer(obj => ProcessTimer(), null, Timeout.Infinite, Timeout.Infinite); m_ndxerProfiles = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.USER_PROFILE); m_ndxerClients = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.HUB_CLIENT); m_ndxerClientsStatus = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.CLIENT_STATUS); m_ndxerProfilesMgmnt = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.PROFILE_MGMNT_MODE); m_ndxerClientsEnv = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.CLIENT_ENV); m_onlineClients = new ActiveClientsQueue(); m_cxnReqProcessors = new Dictionary <Message_t, Func <Message, Message> > { { Message_t.NewConnection, ProcessNewConnectionReq }, { Message_t.Resume, ProcessResumeConnectionReq }, { Message_t.Start, ProcessStartMessage }, { Message_t.Sync, ProcessSyncMessage } }; m_msgProcessors = new Dictionary <Message_t, Func <Message, uint, Message> > { { Message_t.Close, ProcessCloseMessage }, { Message_t.Null, ProcessNullMessage }, { Message_t.SetInfo, ProcessSetInfoMessage }, { Message_t.Log, ProcessLogMessage } }; RegisterHandlers(); AddDownload(Names.ConnectionReqFile); }
public string Encrypt(string clearText) { StringBuilder output = new StringBuilder(); KeyIndexer key = new KeyIndexer(); for (int i = 0; i < Key.Length; i++) { for (int j = 0; j < alphabet.Length; j++) { if (Key[i] == alphabet[j]) { key.Add(i, j); } } } key.KeyedBy = KeyedBy.Value; for (int i = 0; i < Key.Length; i++) { for (int j = key[i]; j < clearText.Length; j += Key.Length) { output.Append(clearText[j]); } } return(output.ToString()); }
public UnitForm(IDatumProvider srcUnits, IDatum datum = null) { Assert(srcUnits != null); Assert(datum == null || datum is Unit); InitializeComponent(); m_ndxerUnits = new KeyIndexer(srcUnits); if (datum != null) { m_datum = datum as Unit; m_tsbReload.Click += delegate { FillForm(); }; m_ndxerUnits.DatumDeleted += UnitsIndexer_DatumChanged; m_ndxerUnits.DatumReplaced += UnitsIndexer_DatumChanged; FillForm(); } m_tbName.TextChanged += delegate { UpdateUI(); }; m_tsbSave.Click += Save_Click; ConnectAsync(); }
//protected: protected override void OnLoad(EventArgs e) { m_ndxerTableGen = new KeyIndexer(AppContext.TableManager.TablesGeneration.DataProvider); m_ndxerTableGen.Connect(); var tm = AppContext.TableManager.Tables; foreach (IDataTable table in AppContext.TableManager.Tables) { var lvi = new ListViewItem(table.Name, 0) { Tag = table }; m_lvTables.Items.Add(lvi); } m_lvTables.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); var wp = AppContext.Settings.UserSettings.WindowPlacement[OPT_KEY]; if (wp != null) { Bounds = wp; } base.OnLoad(e); }
public ProductForm(IDatumProvider srcProduct, IDatum datum = null) { Assert(srcProduct != null); Assert(datum == null || datum is Product); InitializeComponent(); m_ndxerProducts = new KeyIndexer(srcProduct); if (datum != null) { m_datum = datum as Product; FillForm(); m_tsbReload.Click += delegate { FillForm(); }; } //handlers m_tsbSave.Click += Save_Click; m_ndxerProducts.DatumDeleted += ProductsIndexer_DatumChanged; m_ndxerProducts.DatumReplaced += ProductsIndexer_DatumChanged; EventHandler txtChangedHandler = delegate { UpdateUI(); }; m_tbSubHeading.TextChanged += txtChangedHandler; m_tbName.TextChanged += txtChangedHandler; ConnectAsync(); }
public ClientsManagmentWindow() { InitializeComponent(); m_ndxerProfiles = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.USER_PROFILE); m_ndxerStatus = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.CLIENT_STATUS); m_ndxerClientEnv = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.CLIENT_ENV); m_ndxerClients = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.HUB_CLIENT); m_tmFont = new Font(Font, FontStyle.Bold | FontStyle.Italic); }
public ProductMappingChecker(AttrIndexer <uint> ndxerMapProdNber, KeyIndexer ndxerProduct, KeyIndexer ndxerContext) { m_ndxerMapProdNber = ndxerMapProdNber; m_ndxerMapProdNber.Connect(); m_ndxerProduct = ndxerProduct; m_ndxerProduct.Connect(); m_ndxerContext = ndxerContext; m_ndxerContext.Connect(); }
private void UploadDataUpdates_Click(object sender, EventArgs e) { var dlg = new Jobs.ProcessingDialog(); Action upload = () => { KeyIndexer ndxerInc = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.INCREMENT); IEnumerable <uint> ids = from UpdateIncrement inc in ndxerInc.Source.Enumerate() where inc.IsDeployed == false select inc.ID; var netEngin = new NetEngin(AppContext.Settings.NetworkSettings); foreach (var id in ids) { string fileName = id.ToString("X"); string src = Path.Combine(AppPaths.DataUpdateFolder, fileName); string dst = Urls.DataUpdateDirURL + fileName; netEngin.Upload(dst, src); } netEngin.Upload(Urls.DataManifestURL, AppPaths.DataManifestPath); netEngin.Upload(Urls.ManifestURL, AppPaths.ManifestPath); foreach (uint id in ids) { var inc = ndxerInc.Get(id) as UpdateIncrement; inc.DeployTime = DateTime.Now; ndxerInc.Source.Replace(ndxerInc.IndexOf(id), inc); } }; Action <Task> onErr = t => { dlg.Dispose(); this.ShowError(t.Exception.InnerException.Message); }; Action onSuccess = () => { dlg.Dispose(); m_tsbUploadDataUpdates.Enabled = false; }; var task = new Task(upload, TaskCreationOptions.LongRunning); task.OnSuccess(onSuccess); task.OnError(onErr); task.Start(); dlg.ShowDialog(Parent); }
public ProfileForm(IDatumProvider dp, UserProfile datum = null) { Dbg.Assert(dp != null); InitializeComponent(); m_ndxProfiles = new KeyIndexer(dp); if (datum != null) { m_datum = datum; m_tsbReload.Click += Reload_Click; } }
public ProfilesWindow() { InitializeComponent(); m_dpProfiles = AppContext.TableManager.Profiles.DataProvider; m_ndxerProfiles = new KeyIndexer(m_dpProfiles); m_ndxerMgmntMode = new KeyIndexer(AppContext.TableManager.ProfileManagementMode.DataProvider); m_colSorters = new Dictionary <ColumnDataType_t, Func <int, IColumnSorter> > { { ColumnDataType_t.Integer, ndxCol => new IntegerColumnSorter(ndxCol) }, { ColumnDataType_t.Text, ndxCol => new TextColumnSorter(ndxCol) }, }; }
public SpotValueChecker(IDatumProvider spotValues, KeyIndexer labels, KeyIndexer prodMappings) { Assert(spotValues != null); Assert(labels != null); Assert(prodMappings != null); m_srcSpotValues = spotValues; m_srcSpotValues.Connect(); m_ProductMappings = prodMappings; m_ProductMappings.Connect(); m_labels = labels; m_labels.Connect(); }
public CurrencyForm(IDatumProvider currencyProvider, IDatum datum = null) { Assert(currencyProvider != null); Assert(datum == null || datum is Currency); InitializeComponent(); m_ndxerCurrencies = new KeyIndexer(currencyProvider); Predicate <IDatum> filter; if (datum != null) { m_datum = datum as Currency; filter = d => { var ctry = d as Country; return(!ctry.Disabled || ctry.ID == m_datum.CountryID); }; m_ndxerCurrencies.DatumDeleted += CurrenciesIndexer_DatumChanged; m_ndxerCurrencies.DatumReplaced += CurrenciesIndexer_DatumChanged; m_tsbReload.Click += delegate { FillForm(); }; m_cbCountries.SelectedIndexChanged += Countries_SelectedIndexChanged; } else { filter = ctry => !(ctry as Country).Disabled; } var dp = new DatumProvider(AppContext.TableManager.Countries.DataProvider, filter); m_ndxerCountries = new KeyIndexer(dp); //handlers m_ndxerCountries.DatumDeleted += CountriesIndexer_DatumDeleted; m_ndxerCountries.DatumInserted += CountriesIndexer_DatumInserted; m_ndxerCountries.DatumReplaced += CountriesIndexer_DatumReplaced; m_tsbAddCountry.Click += AddCountry_Click; m_tsbSave.Click += Save_Click; m_tbName.TextChanged += delegate { UpdateUI(); }; }
public KeyIndexer GetKeyIndexer(uint idTable) { Assert(AppContext.TableManager.GetTable(idTable) != null); lock (m_lock) { KeyIndexer ndxer = m_keysIndexers.Find(x => x.Source.DataSource.ID == idTable); if (ndxer == null) { ndxer = new KeyIndexer(GetDataProvider(idTable)); ndxer.Connect(); m_keysIndexers.Add(ndxer); } return(ndxer); } }
public DataSuppliersForm(IDatumProvider srcSupplier, IDatum datum) { Assert(srcSupplier != null); Assert(datum != null); Assert(datum is DataSupplier); InitializeComponent(); m_datum = datum as DataSupplier; m_ndxerSuppliers = new KeyIndexer(AppContext.TableManager.Suppiers.DataProvider); //handlers m_ndxerSuppliers.DatumDeleted += SuppliersIndexer_DatumChanged; m_ndxerSuppliers.DatumReplaced += SuppliersIndexer_DatumChanged; m_tbName.TextChanged += delegate { UpdateUI(); }; m_tsbReload.Click += delegate { FillForm(); }; m_tsbSave.Click += Save_Click; FillForm(); ConnectAsync(); }
public PlaceForm(IDatumProvider dataProvider, IDatum datum = null) { Assert(dataProvider != null); Assert(datum == null || datum is Place); InitializeComponent(); m_ndxerPlaces = new KeyIndexer(dataProvider); if (datum != null) { m_datum = datum as Place; var dp = new DatumProvider(AppContext.TableManager.Countries.DataProvider, d => { var ctry = d as Country; return(!ctry.Disabled || ctry.ID == m_datum.CountryID); }); m_ndxerCountries = new KeyIndexer(dp); m_ndxerPlaces.DatumDeleted += PlacesIndexer_DatumChanged; m_ndxerPlaces.DatumReplaced += PlacesIndexer_DatumChanged; m_tsbReload.Click += delegate { FillForm(); }; } else { m_ndxerCountries = new KeyIndexer(AppContext.TableManager.Countries.RowProvider); } //handlers m_ndxerCountries.DatumDeleted += CountriesIndexer_DatumDeleted; m_ndxerCountries.DatumInserted += CountriesIndexer_DatumInserted; m_ndxerCountries.DatumReplaced += CountriesIndexer_DatumReplaced; //m_tsbAddCountry.Click += AddCountry_Click; m_tsbSave.Click += Save_Click; m_tbName.TextChanged += delegate { UpdateUI(); }; m_cbCountries.SelectedIndexChanged += Countries_SelectedIndexChanged; }
/// <summary> /// Set the data before serialization /// </summary> /// <param name="data">The list of </param> public void SetData(IList <ContentCatalogDataEntry> data) { if (data == null) { return; } var providers = new KeyIndexer <string>(data.Select(s => s.Provider), 10); var internalIds = new KeyIndexer <string>(data.Select(s => s.InternalId), data.Count); var keys = new KeyIndexer <object>(data.SelectMany(s => s.Keys), data.Count * 3); var types = new KeyIndexer <Type>(data.Select(s => s.ResourceType), 50); keys.Add(data.SelectMany(s => s.Dependencies)); var keyIndexToEntries = new KeyIndexer <List <ContentCatalogDataEntry>, object>(keys.values, s => new List <ContentCatalogDataEntry>(), keys.values.Count); var entryToIndex = new Dictionary <ContentCatalogDataEntry, int>(data.Count); var extraDataList = new List <byte>(); var entryIndexToExtraDataIndex = new Dictionary <int, int>(); int extraDataIndex = 0; //create buckets of key to data entry for (int i = 0; i < data.Count; i++) { var e = data[i]; int extraDataOffset = -1; if (e.Data != null) { var len = SerializationUtilities.WriteObjectToByteList(e.Data, extraDataList); if (len > 0) { extraDataOffset = extraDataIndex; extraDataIndex += len; } } entryIndexToExtraDataIndex.Add(i, extraDataOffset); entryToIndex.Add(e, i); foreach (var k in e.Keys) { keyIndexToEntries[k].Add(e); } } m_ExtraDataString = Convert.ToBase64String(extraDataList.ToArray()); //create extra entries for dependency sets Dictionary <int, object> hashSources = new Dictionary <int, object>(); int originalEntryCount = data.Count; for (int i = 0; i < originalEntryCount; i++) { var entry = data[i]; if (entry.Dependencies == null || entry.Dependencies.Count < 2) { continue; } int hashCode = CalculateCollectedHash(entry.Dependencies, hashSources); bool isNew = false; keys.Add(hashCode, ref isNew); if (isNew) { //if this combination of dependecies is new, add a new entry and add its key to all contained entries var deps = entry.Dependencies.Select(d => keyIndexToEntries[d][0]).ToList(); keyIndexToEntries.Add(hashCode, deps); foreach (var dep in deps) { dep.Keys.Add(hashCode); } } //reset the dependency list to only contain the key of the new set entry.Dependencies.Clear(); entry.Dependencies.Add(hashCode); } //serialize internal ids and providers m_InternalIds = internalIds.values.ToArray(); m_ProviderIds = providers.values.ToArray(); m_resourceTypes = types.values.Select(t => new SerializedType() { Value = t }).ToArray(); m_Keys = keys.values.Where(x => x != null) .Select(x => x.ToString()) .ToArray(); //serialize entries { var entryData = new byte[data.Count * k_ByteSize * k_EntryDataItemPerEntry + k_ByteSize]; var entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, data.Count, 0); for (int i = 0; i < data.Count; i++) { var e = data[i]; entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, internalIds.map[e.InternalId], entryDataOffset); entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, providers.map[e.Provider], entryDataOffset); entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, e.Dependencies.Count == 0 ? -1 : keyIndexToEntries.map[e.Dependencies[0]], entryDataOffset); entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, e.ComputeDependencyHash(), entryDataOffset); entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, entryIndexToExtraDataIndex[i], entryDataOffset); entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, keys.map[e.Keys.First()], entryDataOffset); entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, types.map[e.ResourceType], entryDataOffset); } m_EntryDataString = Convert.ToBase64String(entryData); } //serialize keys and mappings { var entryCount = keyIndexToEntries.values.Aggregate(0, (a, s) => a += s.Count); var bucketData = new byte[4 + keys.values.Count * 8 + entryCount * 4]; var keyData = new List <byte>(keys.values.Count * 10); keyData.AddRange(BitConverter.GetBytes(keys.values.Count)); int keyDataOffset = 4; int bucketDataOffset = SerializationUtilities.WriteInt32ToByteArray(bucketData, keys.values.Count, 0); for (int i = 0; i < keys.values.Count; i++) { var key = keys.values[i]; bucketDataOffset = SerializationUtilities.WriteInt32ToByteArray(bucketData, keyDataOffset, bucketDataOffset); keyDataOffset += SerializationUtilities.WriteObjectToByteList(key, keyData); var entries = keyIndexToEntries[key]; bucketDataOffset = SerializationUtilities.WriteInt32ToByteArray(bucketData, entries.Count, bucketDataOffset); foreach (var e in entries) { bucketDataOffset = SerializationUtilities.WriteInt32ToByteArray(bucketData, entryToIndex[e], bucketDataOffset); } } m_BucketDataString = Convert.ToBase64String(bucketData); m_KeyDataString = Convert.ToBase64String(keyData.ToArray()); } }
public string Decrypt(string cipherText) { int[] num = new int[Key.Length]; int[] back = new int[Key.Length]; string[] columns = new string[Key.Length]; int minNum; StringBuilder output = new StringBuilder(); minNum = cipherText.Length / Key.Length; KeyIndexer key = new KeyIndexer(); for (int i = 0; i < Key.Length; i++) { for (int j = 0; j < alphabet.Length; j++) { if (Key[i] == alphabet[j]) { key.Add(i, j); } } } key.ReindexValues(); for (int i = 0; i < num.Length; i++) { num[i] = minNum; back[key[i]] = i; } int k = 0; for (int j = minNum * Key.Length; j < cipherText.Length; j++) { num[key[k++]]++; } for (int i = 0; i < Key.Length; i++) { columns[back[i]] = cipherText.Substring(0, num[i]); cipherText = cipherText.Substring(num[i], cipherText.Length - num[i]); } for (int i = 0; i < minNum + 1; i++) { for (int j = 0; j < columns.Length; j++) { if (columns[j].Length > i) { output.Append(columns[j][i]); } } } return(output.ToString()); //StringBuilder output = new StringBuilder(cipherText.ToUpper()); //StringBuilder descramble = new StringBuilder(cipherText.ToUpper()); //Dictionary<int, int> temp = new Dictionary<int, int>(); //for (int i = 0; i < Key.Length; i++) //{ // for (int j = 0; j < alphabet.Length; j++) // { // if (Key[i] == alphabet[j]) // { // temp.Add(j, i); // } // } //} //List<int> locations = new List<int>(temp.Keys); //locations.Sort(); //Dictionary<int, int> indices = new Dictionary<int, int>(); //for (int i = 0; i < locations.Count; i++) //{ // indices.Add(i, temp[locations[i]]); //} //int rows = output.Length / Key.Length; //if (output.Length % Key.Length != 0) //{ // rows++; //} //int k = 0; //for (int j = 0; j < rows; j++) //{ // for (int i = j; i < output.Length; i += rows) // { // descramble[k++] = cipherText[i]; // } //} //k = 0; //for (int j = 0; j < Key.Length; j++) //{ // for (int i = 0; i < output.Length; i += Key.Length) // { // if (i + indices[j] < output.Length && i + j < output.Length) // { // output[i + indices[j]] = descramble[j + i]; // } // } //} //return output.ToString(); }
public void Start() { Assert(IsListening == false); Assert(IsDisposed == false); IEnumerable <IDataTable> tables = AppContext.TableManager.DeployableTables.Add( AppContext.TableManager.TRLabels, AppContext.TableManager.TRSpotValues); foreach (IDataTable tbl in tables) { uint idTable = tbl.ID; Action <IDataRow> rowReplacing = delegate(IDataRow row) { if (!Disabled) { m_replacingCache.Add(Tuple.Create(idTable, row)); } }; Action <IDataRow> rowInserted = delegate(IDataRow row) { if (!Disabled) { for (int i = 0; i < m_replacingCache.Count; ++i) { if (m_replacingCache[i].Item1 == idTable && m_replacingCache[i].Item2.ID == row.ID) { var obj = row as ITaggedRow; if (obj == null || !obj.Disabled) { LogAction(row, idTable, ActionCode_t.ReplaceRow); } else { LogAction(row, idTable, ActionCode_t.DeleteRow); } m_replacingCache.RemoveAt(i); return; } } LogAction(row, idTable, ActionCode_t.AddRow); } }; Action <IDataRow> rowReplaced = delegate(IDataRow row) { if (!Disabled) { for (int i = 0; i < m_replacingCache.Count; ++i) { if (m_replacingCache[i].Item1 == idTable && m_replacingCache[i].Item2.ID == row.ID) { var obj = row as ITaggedRow; if (obj == null || !obj.Disabled) { LogAction(row, idTable, ActionCode_t.ReplaceRow); } else { LogAction(row, idTable, ActionCode_t.DeleteRow); } m_replacingCache.RemoveAt(i); return; } } LogAction(row, idTable, ActionCode_t.ReplaceRow); } }; Action <IDataRow> rowDeleted = delegate(IDataRow row) { if (!Disabled) { for (int i = 0; i < m_replacingCache.Count; ++i) { if (m_replacingCache[i].Item1 == idTable && m_replacingCache[i].Item2.ID == row.ID) { return; } } LogAction(row, idTable, ActionCode_t.DeleteRow); } }; var indexer = new KeyIndexer(tbl.DataProvider); indexer.Connect(); m_dataIndexers.Add(indexer); indexer.DatumReplacing += rowReplacing; indexer.DatumDeleted += rowDeleted; indexer.DatumInserted += rowInserted; indexer.DatumReplaced += rowReplaced; } IsListening = true; }
/// <summary> /// Set the data before serialization /// </summary> /// <param name="data">The list of </param> public void SetData(IList <ContentCatalogDataEntry> data) { if (data == null) { return; } var providers = new KeyIndexer <string>(data.Select(s => s.Provider), 10); var internalIds = new KeyIndexer <string>(data.Select(s => s.InternalId), data.Count); var keys = new KeyIndexer <object>(data.SelectMany(s => s.Keys), data.Count * 3); keys.Add(data.SelectMany(s => s.Dependencies)); var keyIndexToEntries = new KeyIndexer <List <ContentCatalogDataEntry>, object>(keys.values, s => new List <ContentCatalogDataEntry>(), keys.values.Count); var entryToIndex = new Dictionary <ContentCatalogDataEntry, int>(data.Count); var extraDataList = new List <byte>(); var entryIndexToExtraDataIndex = new Dictionary <int, int>(); int extraDataIndex = 0; //create buckets of key to data entry for (int i = 0; i < data.Count; i++) { var e = data[i]; int extraDataOffset = -1; if (e.Data != null) { var len = SerializationUtilities.WriteObjectToByteList(e.Data, extraDataList); if (len > 0) { extraDataOffset = extraDataIndex; extraDataIndex += len; } } entryIndexToExtraDataIndex.Add(i, extraDataOffset); entryToIndex.Add(e, i); foreach (var k in e.Keys) { keyIndexToEntries[k].Add(e); } } m_ExtraDataString = Convert.ToBase64String(extraDataList.ToArray()); //create extra entries for dependency sets int originalEntryCount = data.Count; for (int i = 0; i < originalEntryCount; i++) { var entry = data[i]; if (entry.Dependencies == null || entry.Dependencies.Count < 2) { continue; } //seed and and factor values taken from https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations int hashCode = 1009; foreach (var dep in entry.Dependencies) { hashCode = hashCode * 9176 + dep.GetHashCode(); } bool isNew = false; keys.Add(hashCode, ref isNew); if (isNew) { //if this combination of dependecies is new, add a new entry and add its key to all contained entries var deps = entry.Dependencies.Select(d => keyIndexToEntries[d][0]).ToList(); keyIndexToEntries.Add(hashCode, deps); foreach (var dep in deps) { dep.Keys.Add(hashCode); } } //reset the dependency list to only contain the key of the new set entry.Dependencies.Clear(); entry.Dependencies.Add(hashCode); } //serialize internal ids and providers m_InternalIds = internalIds.values.ToArray(); m_ProviderIds = providers.values.ToArray(); //serialize entries { var entryData = new byte[data.Count * 4 * 5 + 4]; var entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, data.Count, 0); for (int i = 0; i < data.Count; i++) { var e = data[i]; entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, internalIds.map[e.InternalId], entryDataOffset); entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, providers.map[e.Provider], entryDataOffset); entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, e.Dependencies.Count == 0 ? -1 : keyIndexToEntries.map[e.Dependencies[0]], entryDataOffset); entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, e.ComputeDependencyHash(), entryDataOffset); entryDataOffset = SerializationUtilities.WriteInt32ToByteArray(entryData, entryIndexToExtraDataIndex[i], entryDataOffset); } m_EntryDataString = Convert.ToBase64String(entryData); } //serialize keys and mappings { var entryCount = keyIndexToEntries.values.Aggregate(0, (a, s) => a += s.Count); var bucketData = new byte[4 + keys.values.Count * 8 + entryCount * 4]; var keyData = new List <byte>(keys.values.Count * 10); keyData.AddRange(BitConverter.GetBytes(keys.values.Count)); int keyDataOffset = 4; int bucketDataOffset = SerializationUtilities.WriteInt32ToByteArray(bucketData, keys.values.Count, 0); for (int i = 0; i < keys.values.Count; i++) { var key = keys.values[i]; bucketDataOffset = SerializationUtilities.WriteInt32ToByteArray(bucketData, keyDataOffset, bucketDataOffset); keyDataOffset += SerializationUtilities.WriteObjectToByteList(key, keyData); var entries = keyIndexToEntries[key]; bucketDataOffset = SerializationUtilities.WriteInt32ToByteArray(bucketData, entries.Count, bucketDataOffset); foreach (var e in entries) { bucketDataOffset = SerializationUtilities.WriteInt32ToByteArray(bucketData, entryToIndex[e], bucketDataOffset); } } m_BucketDataString = Convert.ToBase64String(bucketData); m_KeyDataString = Convert.ToBase64String(keyData.ToArray()); } }
public string Decrypt(string cipherText) { int[] num = new int[Key.Length]; int[] back = new int[Key.Length]; string[] columns = new string[Key.Length]; int minNum; StringBuilder output = new StringBuilder(); minNum = cipherText.Length / Key.Length; KeyIndexer key = new KeyIndexer(); for (int i = 0; i < Key.Length; i++) { for (int j = 0; j < alphabet.Length; j++) { if (Key[i] == alphabet[j]) { key.Add(i, j); } } } key.ReindexValues(); for (int i = 0; i < num.Length; i++) { num[i] = minNum; back[key[i]] = i; } int k = 0; for (int j = minNum * Key.Length; j < cipherText.Length; j++) { num[key[k++]]++; } for (int i = 0; i < Key.Length; i++) { columns[back[i]] = cipherText.Substring(0, num[i]); cipherText = cipherText.Substring(num[i], cipherText.Length - num[i]); } for (int i = 0; i < minNum + 1; i++) { for (int j = 0; j < columns.Length; j++) { if (columns[j].Length > i) { output.Append(columns[j][i]); } } } return output.ToString(); //StringBuilder output = new StringBuilder(cipherText.ToUpper()); //StringBuilder descramble = new StringBuilder(cipherText.ToUpper()); //Dictionary<int, int> temp = new Dictionary<int, int>(); //for (int i = 0; i < Key.Length; i++) //{ // for (int j = 0; j < alphabet.Length; j++) // { // if (Key[i] == alphabet[j]) // { // temp.Add(j, i); // } // } //} //List<int> locations = new List<int>(temp.Keys); //locations.Sort(); //Dictionary<int, int> indices = new Dictionary<int, int>(); //for (int i = 0; i < locations.Count; i++) //{ // indices.Add(i, temp[locations[i]]); //} //int rows = output.Length / Key.Length; //if (output.Length % Key.Length != 0) //{ // rows++; //} //int k = 0; //for (int j = 0; j < rows; j++) //{ // for (int i = j; i < output.Length; i += rows) // { // descramble[k++] = cipherText[i]; // } //} //k = 0; //for (int j = 0; j < Key.Length; j++) //{ // for (int i = 0; i < output.Length; i += Key.Length) // { // if (i + indices[j] < output.Length && i + j < output.Length) // { // output[i + indices[j]] = descramble[j + i]; // } // } //} //return output.ToString(); }
public string Encrypt(string clearText) { StringBuilder output = new StringBuilder(); KeyIndexer key = new KeyIndexer(); for (int i = 0; i < Key.Length; i++) { for (int j = 0; j < alphabet.Length; j++) { if (Key[i] == alphabet[j]) { key.Add(i, j); } } } key.KeyedBy = KeyedBy.Value; for (int i = 0; i < Key.Length; i++) { for (int j = key[i]; j < clearText.Length; j += Key.Length) { output.Append(clearText[j]); } } return output.ToString(); }
private void UploadAppUpdates_Click(object sender, EventArgs e) { var filesNames = new Dictionary <AppArchitecture_t, string> { { AppArchitecture_t.Win7SP1, WIN7SP1_UPDATE_FILENAME }, { AppArchitecture_t.Win7SP1X64, WIN7SP1X64_UPADTE_FILENAME }, { AppArchitecture_t.WinXP, WINXP_UPADTE_FILENAME } }; var waitDlg = new Jobs.ProcessingDialog(); Action run = () => { KeyIndexer ndxer = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.APP_UPDATE); var seq = (from AppUpdate up in ndxer.Source.Enumerate() where up.DeployTime == AppUpdate.NOT_YET select up).ToArray(); //maj app manifest + manifest global Dictionary <AppArchitecture_t, string> appManifest; try { appManifest = UpdateEngin.ReadAppManifest(AppPaths.AppManifestPath); } catch (Exception ex) { TextLogger.Warning(ex.Message); appManifest = new Dictionary <AppArchitecture_t, string>(); } IUpdateManifest gManifest; try { gManifest = UpdateEngin.ReadUpdateManifest(AppPaths.ManifestPath); } catch (Exception ex) { TextLogger.Warning(ex.Message); gManifest = new UpdateManifest(0, 0); } var netEngin = new NetEngin(AppContext.Settings.NetworkSettings); foreach (AppUpdate up in seq) { gManifest.Versions[up.AppArchitecture] = up.Version; appManifest[up.AppArchitecture] = filesNames[up.AppArchitecture]; string srcFileName = up.ID.ToString("X"); string destFileName = filesNames[up.AppArchitecture]; string dst = Urls.AppUpdateDirURL + destFileName; waitDlg.Message = $"Transfert du fichier {destFileName}. Cette opération peut durer plusieurs minutes."; netEngin.Upload(dst, Path.Combine(AppPaths.AppUpdateFolder, srcFileName)); up.DeployTime = DateTime.Now; ndxer.Source.Replace(ndxer.IndexOf(up.ID), up); } waitDlg.Message = "Transfert du manifest des applications..."; UpdateEngin.WriteAppManifest(AppPaths.AppManifestPath, appManifest); netEngin.Upload(Urls.AppManifestURL, AppPaths.AppManifestPath); waitDlg.Message = "Transfert du manifest global..."; UpdateEngin.WriteUpdateManifest(gManifest, AppPaths.ManifestPath); netEngin.Upload(Urls.ManifestURL, AppPaths.ManifestPath); }; Action onSucces = () => { m_tsbUploadAppUpdates.Enabled = false; waitDlg.Dispose(); }; Action <Task> onErr = t => { waitDlg.Dispose(); this.ShowError(t.Exception.InnerException.Message); TextLogger.Error(t.Exception.InnerException.Message); }; var task = new Task(run, TaskCreationOptions.LongRunning); task.OnSuccess(onSucces); task.OnError(onErr); task.Start(); waitDlg.ShowDialog(this); }
public string Decrypt(string cipherText) { KeyIndexer oto = new KeyIndexer(); for (int i = 0; i < Key.Length; i++) { oto.Add(i, Key[i]); } oto.KeyedBy = KeyedBy.Value; int lastChar = cipherText.Length % 3;//r=0, 2 means no special consideration when decrypting, mod = 1 means single should be double char int numPositions = 2 * (cipherText.Length / 3); if (lastChar != 0) { numPositions++; } int numRows = numPositions / Key.Length; int remainder = numPositions % Key.Length; string[,] pieces = new string[numRows + 1, Key.Length]; int k = 0; for (int i = 0; i < oto.Count; i++) { int x = oto[i]; for (int j = 0; j < numRows + (x < remainder ? 1 : 0); j++) { if ((x & 0x01) == 0) { if ((j & 0x01) == 0) { pieces[j, x] = cipherText[k++].ToString(); if (k < cipherText.Length && !(x == remainder - 1 && lastChar == 1 && j == numRows - 1 + (x < remainder ? 1 : 0))) { pieces[j, x] += cipherText[k++].ToString(); } } else { pieces[j, x] = cipherText[k++].ToString(); } } else { if ((j & 0x01) == 1) { pieces[j, x] = cipherText[k++].ToString(); if (k < cipherText.Length && !(x == remainder - 1 && lastChar == 1 && j == numRows - 1 + (x < remainder ? 1 : 0))) { pieces[j, x] += cipherText[k++].ToString(); } } else { pieces[j, x] = cipherText[k++].ToString(); } } } } StringBuilder output = new StringBuilder(); for (int i = 0; i < numRows + (remainder > 0?1:0); i++) { for (int j = 0; j < Key.Length; j++) { output.Append(pieces[i, j] ?? ""); } } return(output.ToString()); }
static CqlTree() { Span = new KeyIndexer <Range>(QsiNodeProperties.Span); }
static PTree() { RawNode = new KeyIndexer <IPhoenixNode>(new Key <IPhoenixNode>("raw_node")); }