public Dictionary <string, string> DoDeserialisationB()
        {
            int numberItems = 0;
            Dictionary <string, string> readyDict = new Dictionary <string, string>();

            BinaryFormatter formater = new BinaryFormatter();

            // получаем поток, куда будем записывать сериализованный объект
            using (FileStream fs = new FileStream("secretData.xml", FileMode.OpenOrCreate))
            {
                try
                {
                    SerialisationDictionary[] arrayClassDict1 = (SerialisationDictionary[])formater.Deserialize(fs);
                    numberItems = arrayClassDict1.Length;
                    foreach (var ittem in arrayClassDict1)
                    {
                        readyDict.Add(ittem.keyy, ittem.valuee);
                    }
                }
                catch (Exception e)
                {
                    string        messageToWriteFailed = "DE serialisation Exception happen" + e.ToString();
                    LoggingTxtIva ll2 = new LoggingTxtIva(messageToWriteFailed);
                }
            }
            string        message = "DEserialisation process finished";
            LoggingTxtIva ll3     = new LoggingTxtIva(message);

            return(readyDict);
        }
        public void DoSerialisationB(Dictionary <string, string> _inMovePicDictionary)
        {
            // Serialisation -xml serialisation is not possible for dictionary - thats why i use SerialisationDictionary[] for serialisation
            SerialisationDictionary[] arrayClassDict = new SerialisationDictionary[_inMovePicDictionary.Keys.Count()];
            int ii = 0;

            foreach (KeyValuePair <string, string> item in _inMovePicDictionary)
            {
                SerialisationDictionary temp = new SerialisationDictionary();
                temp.methodSet(item);
                arrayClassDict[ii] = temp;
                ii++;
            }

            BinaryFormatter formater = new BinaryFormatter();

            // получаем поток, куда будем записывать сериализованный объект
            using (FileStream fs = new FileStream("secretData.xml", FileMode.OpenOrCreate))
            {
                try
                {
                    formater.Serialize(fs, arrayClassDict);
                }
                catch (Exception e)
                {
                    string        messageToWriteFailed = "Serialisation Exception happen" + e.ToString();
                    LoggingTxtIva ll2 = new LoggingTxtIva(messageToWriteFailed);
                }
            }
        }
Ejemplo n.º 3
0
        public void Move_FileNameExistsMethod(string _fileToCopy, string _destinationDirectory)
        {
            for (int i = 1; i <= NumberOfRetries; i++)
            {
                try
                {
                    int    count        = 1;
                    string fileNameOnly = Path.GetFileNameWithoutExtension(_fileToCopy);
                    string extension    = Path.GetExtension(_fileToCopy);
                    string path         = Path.GetDirectoryName(_fileToCopy);
                    string newFullPath  = _destinationDirectory + fileNameOnly + extension;
                    string newFullName  = _fileToCopy;

                    while (File.Exists(newFullPath))
                    {
                        string tempFileName = string.Format("{0}({1})", fileNameOnly, count++);
                        //newFullPath = Path.Combine(path, tempFileName + extension);
                        newFullName = tempFileName + extension;
                        newFullPath = _destinationDirectory + newFullName;
                    }

                    #region TEST1 here is was experiment to be able to open the file and close it - so no other process access the file !!!
                    try
                    {
                        FileStream fs = System.IO.File.Open(_fileToCopy, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Read, System.IO.FileShare.None);
                        fs.Close();
                    }
                    catch (IOException e)
                    {
                        string        messageToWriteFailed = "Exception happen" + e.ToString();
                        LoggingTxtIva ll2 = new LoggingTxtIva(messageToWriteFailed);
                    }
                    #endregion

                    // Move
                    File.Move(_fileToCopy, newFullPath);
                    Thread.Sleep(10);
                    break;
                }
                catch (IOException e) when(i <= NumberOfRetries)
                {
                    string        messageToWriteFailed = "Exception happen" + e.ToString();
                    LoggingTxtIva ll2 = new LoggingTxtIva(messageToWriteFailed);

                    Thread.Sleep(DelayOnRetry);
                }
            }
        }