コード例 #1
0
        private void SetDeviceBaseProperties(Device prog, JsonData currentDevice,
                                             Dictionary <string, List <File> > filesPerDevice)
        {
            var uniqueId     = currentDevice["UniqueId"].ToString();
            var name         = currentDevice["Name"].ToString();
            var firewallType =
                (FirewallType)Enum.Parse(typeof(FirewallType), currentDevice["FirewallType"].ToString());
            var specialPrograms   = currentDevice["SpecialPrograms"].ToString().Trim();
            var dicSpecialProgram = new Dictionary <ProgramType, int>();
            var startUnlocked     = bool.Parse(currentDevice["StartUnlocked"].ToString());

            if (!string.IsNullOrEmpty(specialPrograms))
            {
                var specialProgramsDef = currentDevice["SpecialPrograms"].ToString().Split(';');
                for (int i = 0; i < specialProgramsDef.Length; i++)
                {
                    var currentProg     = specialProgramsDef[i];
                    var parts           = currentProg.Split(',');
                    var programId       = (ProgramType)Enum.Parse(typeof(ProgramType), parts[0]);
                    var programUniqueId = parts[1];
                    dicSpecialProgram[programId] = int.Parse(programUniqueId);
                }
            }

            prog.Id              = uniqueId;
            prog.UniqueId        = prog.Id.GetHashCode();
            prog.Name            = name;
            prog.FirewallType    = firewallType;
            prog.SpecialPrograms = dicSpecialProgram;
            prog.StartUnlocked   = startUnlocked;

            FileSystem fileSystem = new FileSystem();

            prog.FileSystem = fileSystem;

            var files = filesPerDevice[uniqueId];

            for (int i = 0; i < files.Count; i++)
            {
                var file = files[i];

                Directory dir;
                fileSystem.CreateDiretory(file.PathString, out dir);
                fileSystem.AddFileWithoutValidation(dir, file);
            }
        }