public static void UpdateSource(Com_HashObject source, ref components.Components.DataContainer.DataContainer dc) { Dictionary<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, DataTableCreateMethod> dTCreator = new Dictionary<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, DataTableCreateMethod>(); Dictionary<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, DataSourceReader> dSReader = new Dictionary<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, DataSourceReader>(); // data table creators dTCreator[components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Product] = CreateDataTableForProduct; dTCreator[components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative] = CreateDataTableForAlternative; dTCreator[components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Client] = CreateDataTableForCard; dTCreator[components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Order] = CreateDataTableForOrder; // source readers dSReader[components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Product] = ReadProduct; dSReader[components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative] = ReadAlternative; dSReader[components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Client] = ReadCard; // order reader is not implemented because of ugc. // steps to load data // 1. load new data or load existed // 2. create data sources // 3. fill data sources with loaded data DataSourceItem dSrcItem = new DataSourceItem(); DataTable __tempDataTable = new DataTable(); bool fOK = false; string __tempFilePath = string.Empty; // loop by profiles // [foreach 1 - profile] foreach (DictionaryEntry profileEntry in source) { foreach (KeyValuePair<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, DataSourceReader> currentSourceReader in dSReader) { // create data table __tempDataTable = dTCreator[currentSourceReader.Key].Invoke(); __tempDataTable.TableName = string.Format("{0}_{1:D2}", currentSourceReader.Key, int.Parse(profileEntry.Key.ToString())); //dSrcItem = new DataSourceItem(dTCreator[currentSourceReader.Key].Invoke(), currentSourceReader.Key.ToString()); // if there is remote file // we'll copy and load it if (!source[profileEntry.Key][CoreConst.SOURCE_REMOTE].GetValue(currentSourceReader.Key).ToString().Equals(string.Empty)) { Com_WinApi.OutputDebugString("copy start"); __tempFilePath = source[profileEntry.Key][CoreConst.SOURCE_TEMP].GetValue(currentSourceReader.Key).ToString(); fOK = Com_WinApi.CopyFile(source[profileEntry.Key][CoreConst.SOURCE_REMOTE].GetValue(currentSourceReader.Key).ToString(), __tempFilePath, false); Com_WinApi.OutputDebugString("copy end"); if (fOK && Com_WinApi.PathFileExists(__tempFilePath)) { dSReader[currentSourceReader.Key].Invoke(__tempFilePath, ref __tempDataTable, int.Parse(profileEntry.Key.ToString())); __tempDataTable.WriteXml(source[profileEntry.Key][CoreConst.SOURCE_LOCAL].GetValue(currentSourceReader.Key).ToString()); } try { Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(__tempFilePath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } catch { } } else // check if there is local file we'll load it { __tempFilePath = source[profileEntry.Key][CoreConst.SOURCE_LOCAL].GetValue(currentSourceReader.Key).ToString(); if (Com_WinApi.PathFileExists(__tempFilePath)) try { dSrcItem.Source.ReadXml(__tempFilePath); } catch { } } dSrcItem = new DataSourceItem(__tempDataTable); dc.Storages.Add(dSrcItem); } // ugc __tempDataTable = dTCreator[components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Order].Invoke(); __tempDataTable.TableName = string.Format("{0}_{1:D2}", components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Order, int.Parse(profileEntry.Key.ToString())); dSrcItem = new DataSourceItem(__tempDataTable); dSrcItem.Properties = DataWorkShared.GetStandartOrderInfoStructure2(); dc.Storages.Add(dSrcItem); }// end of [foreach 1 - profile] }
// get available data public static Com_HashObject CheckGetDataSource(bool updateOnly) { /* main variables */ //SortedList remoteFiles = new SortedList(); //SortedList localFiles = new SortedList(); //string[] remoteFiles = new string[3]; //string[] localFiles = new string[3]; // source file container Com_HashObject loadedData = new Com_HashObject(); // local data container Com_HashObject fileData = new Com_HashObject(); // data comparer DateTime exchangeFileDateTime = new DateTime(); // source file name patterns Com_HashObject sourcePattern = new Com_HashObject(); // file name pattern arguments //object[] patternArguments = new object[4]; Com_HashObject patternArguments2 = new Com_HashObject(); List<components.Shared.Enums.Enu_SourceEnums.pdDataItemType> allAvailableSources = new List<components.Shared.Enums.Enu_SourceEnums.pdDataItemType>() { components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Product, components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative, components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Client }; /* Dictionary<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, string> remoteFiles = new Dictionary<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, string>(); Dictionary<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, string> localFiles = new Dictionary<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, string>(); Dictionary<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, string> tempFiles = new Dictionary<components.Shared.Enums.Enu_SourceEnums.pdDataItemType, string>(); */ // patternt for remote files sourcePattern[CoreConst.SOURCE_REMOTE].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Product, "{0}\\Art_{2:D2}{1:D2}.SDF"); sourcePattern[CoreConst.SOURCE_REMOTE].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative, "{0}\\Alt_{2:D2}{1:D2}.SDF"); sourcePattern[CoreConst.SOURCE_REMOTE].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Client, "{0}\\Cli_{2:D2}.SDF"); // patternt for temporary files sourcePattern[CoreConst.SOURCE_TEMP].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Product, "{0}\\Art_{2:D2}{1:D2}.tmp"); sourcePattern[CoreConst.SOURCE_TEMP].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative, "{0}\\Alt_{2:D2}{1:D2}.tmp"); sourcePattern[CoreConst.SOURCE_TEMP].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Client, "{0}\\Cli_{2:D2}.tmp"); // patternt for local files sourcePattern[CoreConst.SOURCE_LOCAL].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Product, "{0}\\Products_{2:D2}{1:D2}.xml"); sourcePattern[CoreConst.SOURCE_LOCAL].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative, "{0}\\Alternative_{2:D2}{1:D2}.xml"); sourcePattern[CoreConst.SOURCE_LOCAL].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Client, "{0}\\Clients_{2:D2}.xml"); // patternt arguments patternArguments2.SetValue("PATH", ConfigManager.Instance.CommonConfiguration.Path_Exchnage); patternArguments2.SetValue("SUBUNIT", driver.Config.ConfigManager.Instance.CommonConfiguration.APP_SubUnit); patternArguments2.SetValue("PROFILEID", string.Empty); //Hashtable load = new Hashtable(); //string[] load_profile = new string[3] { "", "", "" }; if (driver.Config.ConfigManager.Instance.CommonConfiguration.PROFILES_updateDateTime == null) driver.Config.ConfigManager.Instance.CommonConfiguration.PROFILES_updateDateTime = new Hashtable(); //bool hasUpdates = false; /* loop by all available profiles */ // [foreach 1] int dateTimeIndex = 0; Hashtable profile = new Hashtable(); foreach (DictionaryEntry de in driver.Config.ConfigManager.Instance.CommonConfiguration.PROFILES_Items) { // removing all previous files fileData.Clear(); try { profile = (Hashtable)de.Value; } catch { } /* checking for updates */ Com_WinApi.OutputDebugString("CheckUpdate_begin"); // profile index (ID) patternArguments2.SetValue("PROFILEID", int.Parse(de.Key.ToString())); // = remote files // set value at 0 index with path to remote directory (exchange folder) // if profile doesn't have that path we'll set it with default path if (profile == null || !profile.ContainsKey("SOURCE") || profile["SOURCE"] == null) patternArguments2.SetValue("PATH", ConfigManager.Instance.CommonConfiguration.Path_Exchnage); else patternArguments2.SetValue("PATH", profile["SOURCE"].ToString()); // set all remote files fileData[CoreConst.SOURCE_REMOTE].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Product, string.Format(sourcePattern[CoreConst.SOURCE_REMOTE].GetValue<string>(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Product), patternArguments2.ValuesToArray())); // sourcePattern[CoreConst.SOURCE_REMOTE].GetValue() profileSourceDir + "\\" + string.Format("Art_{1:D2}{0:D2}", driver.Config.ConfigManager.Instance.CommonConfiguration.APP_SubUnit, int.Parse(de.Key.ToString())) + ".SDF"; fileData[CoreConst.SOURCE_REMOTE].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative, string.Format(sourcePattern[CoreConst.SOURCE_REMOTE].GetValue<string>(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative), patternArguments2.ValuesToArray())); // profileSourceDir + "\\" + string.Format("Alt_{1:D2}{0:D2}", driver.Config.ConfigManager.Instance.CommonConfiguration.APP_SubUnit, int.Parse(de.Key.ToString())) + ".SDF"; fileData[CoreConst.SOURCE_REMOTE].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Client, string.Format(sourcePattern[CoreConst.SOURCE_REMOTE].GetValue<string>(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Client), patternArguments2.ValuesToArray())); //profileSourceDir + "\\" + string.Format("Cli_{0:D2}", int.Parse(de.Key.ToString())) + ".SDF"; // = local files // set value at 0 index with path to local directory (articles folder) patternArguments2.SetValue("PATH", ConfigManager.Instance.CommonConfiguration.Path_Articles); // removing all previous files //fileData.Clear(); // set all local files fileData[CoreConst.SOURCE_LOCAL].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Product, string.Format(sourcePattern[CoreConst.SOURCE_LOCAL].GetValue<string>(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative), patternArguments2.ValuesToArray())); //driver.Config.ConfigManager.Instance.CommonConfiguration.Path_Articles + "\\" + string.Format("Art_{1:D2}{0:D2}", driver.Config.ConfigManager.Instance.CommonConfiguration.APP_SubUnit, int.Parse(de.Key.ToString())) + ".xml"; fileData[CoreConst.SOURCE_LOCAL].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative, string.Format(sourcePattern[CoreConst.SOURCE_LOCAL].GetValue<string>(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative), patternArguments2.ValuesToArray())); //driver.Config.ConfigManager.Instance.CommonConfiguration.Path_Articles + "\\" + string.Format("Alt_{1:D2}{0:D2}", driver.Config.ConfigManager.Instance.CommonConfiguration.APP_SubUnit, int.Parse(de.Key.ToString())) + ".xml"; fileData[CoreConst.SOURCE_LOCAL].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Client, string.Format(sourcePattern[CoreConst.SOURCE_LOCAL].GetValue<string>(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative), patternArguments2.ValuesToArray())); //driver.Config.ConfigManager.Instance.CommonConfiguration.Path_Articles + "\\" + string.Format("Cli_{0:D2}", int.Parse(de.Key.ToString())) + ".xml"; // = temporary files // set value at 0 index with path to temporary directory (temp folder) // uncomment this lisne if it's neccessary to store remote file into temp dir. (Products dir default) patternArguments2.SetValue("PATH", ConfigManager.Instance.CommonConfiguration.Path_Temp); // removing all previous files //fileData.Clear(); // set all temp files fileData[CoreConst.SOURCE_TEMP].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Product, string.Format(sourcePattern[CoreConst.SOURCE_TEMP].GetValue<string>(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative), patternArguments2.ValuesToArray())); //driver.Config.ConfigManager.Instance.CommonConfiguration.Path_Articles + "\\" + string.Format("Art_{1:D2}{0:D2}", driver.Config.ConfigManager.Instance.CommonConfiguration.APP_SubUnit, int.Parse(de.Key.ToString())) + ".tmp"; fileData[CoreConst.SOURCE_TEMP].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative, string.Format(sourcePattern[CoreConst.SOURCE_TEMP].GetValue<string>(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative), patternArguments2.ValuesToArray())); //driver.Config.ConfigManager.Instance.CommonConfiguration.Path_Articles + "\\" + string.Format("Alt_{1:D2}{0:D2}", driver.Config.ConfigManager.Instance.CommonConfiguration.APP_SubUnit, int.Parse(de.Key.ToString())) + ".tmp"; fileData[CoreConst.SOURCE_TEMP].SetValue(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Client, string.Format(sourcePattern[CoreConst.SOURCE_TEMP].GetValue<string>(components.Shared.Enums.Enu_SourceEnums.pdDataItemType.Alternative), patternArguments2.ValuesToArray())); //driver.Config.ConfigManager.Instance.CommonConfiguration.Path_Articles + "\\" + string.Format("Cli_{0:D2}", int.Parse(de.Key.ToString())) + ".tmp"; if (!driver.Config.ConfigManager.Instance.CommonConfiguration.PROFILES_updateDateTime.ContainsKey(de.Key)) driver.Config.ConfigManager.Instance.CommonConfiguration.PROFILES_updateDateTime.Add(de.Key, new DateTime[3]); /* ToDo * * loop all server's files and detect for newer date * also detect for deleted files * * if someone of them is newer than local's files * we'll load all them directly. * */ // [foreach 11] check all files related to running profile // remoteFiles contains same keys as localFiles. // so we'll use remoteFiles keys dateTimeIndex = 0; foreach (components.Shared.Enums.Enu_SourceEnums.pdDataItemType sourceKey in allAvailableSources) { // [try 1] try { Com_WinApi.OutputDebugString("checking file " + fileData[CoreConst.SOURCE_REMOTE].GetValue(sourceKey)); loadedData[de.Key][CoreConst.SOURCE_REMOTE].SetValue(sourceKey, string.Empty); loadedData[de.Key][CoreConst.SOURCE_LOCAL].SetValue(sourceKey, fileData[CoreConst.SOURCE_LOCAL].GetValue(sourceKey)); loadedData[de.Key][CoreConst.SOURCE_TEMP].SetValue(sourceKey, fileData[CoreConst.SOURCE_TEMP].GetValue(sourceKey)); // check if remote folder has source file if (updateOnly && AsyncFunc.FileExists(fileData[CoreConst.SOURCE_REMOTE].GetValue<string>(sourceKey), driver.Config.ConfigManager.Instance.CommonConfiguration.APP_RefreshTimeout, CoreConst.SOURCE_REMOTE)) { // get date and time of remote file exchangeFileDateTime = Microsoft.VisualBasic.FileSystem.FileDateTime(fileData[CoreConst.SOURCE_REMOTE].GetValue<string>(sourceKey)); // if remote file datetime is larger than current local file // add this file to loadedData collection for further loading into application // (update is available) if (exchangeFileDateTime > ((DateTime[])driver.Config.ConfigManager.Instance.CommonConfiguration.PROFILES_updateDateTime[de.Key])[dateTimeIndex]) { loadedData[de.Key][CoreConst.SOURCE_REMOTE].SetValue(sourceKey, fileData[CoreConst.SOURCE_REMOTE].GetValue(sourceKey)); ((DateTime[])driver.Config.ConfigManager.Instance.CommonConfiguration.PROFILES_updateDateTime[de.Key.ToString()])[dateTimeIndex] = exchangeFileDateTime; } } // if local file is removed but remote exists // add it for loading if (!AsyncFunc.FileExists(fileData[CoreConst.SOURCE_LOCAL].GetValue<string>(sourceKey), driver.Config.ConfigManager.Instance.CommonConfiguration.APP_RefreshTimeout, CoreConst.SOURCE_LOCAL) && AsyncFunc.FileExists(fileData[CoreConst.SOURCE_REMOTE].GetValue<string>(sourceKey), driver.Config.ConfigManager.Instance.CommonConfiguration.APP_RefreshTimeout, CoreConst.SOURCE_REMOTE)) { loadedData[de.Key][CoreConst.SOURCE_REMOTE].SetValue(sourceKey, fileData[CoreConst.SOURCE_REMOTE].GetValue(sourceKey)); } }// end of try 1 catch (Exception ex) { if (ex.Message == "Timeout" + CoreConst.SOURCE_REMOTE) loadedData[de.Key][CoreConst.SOURCE_REMOTE][CoreConst.CONTAINER_STATE].SetValue(sourceKey, CoreConst.STATE_LAN_ERROR); if (ex.Message == "Timeout" + CoreConst.SOURCE_LOCAL) loadedData[de.Key][CoreConst.SOURCE_LOCAL][CoreConst.CONTAINER_STATE].SetValue(sourceKey, CoreConst.STATE_LAN_ERROR); } dateTimeIndex++; } // end of foreach 11 Com_WinApi.OutputDebugString("CheckUpdate_end"); } // end of foreach 1 return loadedData; }