예제 #1
0
        /// <summary>
        /// if no project settings available, it will be created if user enters all necessary data
        /// </summary>
        /// <returns>status if project settings were created</returns>
        private static bool CreateProject()
        {
            bool result             = false;
            IProjectRepository repo = (IProjectRepository)Program.Kernel.Get(typeof(IProjectRepository));

            Domain.Entity.Project pj = repo.GetSingle();

            if (pj == null)
            {
                using (var setupDialog = (FirstSetupXtraForm)Program.Kernel.Get(typeof(FirstSetupXtraForm)))
                {
                    setupDialog.ShowDialog();
                    if (setupDialog.DialogResult == DialogResult.Cancel)
                    {
                        System.Environment.Exit(0);
                    }
                    pj = repo.GetSingle();
                    if (pj == null)
                    {
                        ApplicationException e = new ApplicationException("Could not find project settings");
                        log.Error(e.Message);
                        throw e;
                    }
                }
            }
            else
            {
                result = true;
            }
            workstationType = pj.WorkstationType;
            log.Info("Project data has been " + (result ? "created" : "retrieved"));
            return(result);
        }
예제 #2
0
 public Workstation GetWorkstationOfType(WorkstationType workstationType)
 {
     if (workstations.ContainsKey(workstationType))
     {
         return(workstations[workstationType]);
     }
     else
     {
         return(null);
     }
 }
예제 #3
0
        void CheckWorkstationType(WorkstationType workstationType)
        {
            var project = importRepo.ProjectRepo.GetSingle();

            if (project.WorkstationType == WorkstationType.Construction &&
                workstationType != WorkstationType.Master)
            {
                var ex = new ImportException(Program.LanguageManager.GetString(StringResources.Import_WrongWorkstationType));
                log.Error(ex.Message);
                throw ex;
            }
        }
예제 #4
0
        public DataImporter(IImportRepository importRepo, IHasher hasher, IEncryptor encryptor)
            : base(hasher, encryptor)
        {
            this.IsDisposed = false;
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["PrismDatabase"];

            HibernateUtil.Initialize(settings.ConnectionString, true);
            this.importRepo = Program.Kernel.Get <IImportRepository>();

            progressMessage = Program.LanguageManager.GetString(StringResources.Import_Progress_Message_Counter) + " {0} / {1} " + ". " +
                              Program.LanguageManager.GetString(StringResources.Import_Progress_Message_Type) + " {2}";

            currentStation = (importRepo.ProjectRepo.GetSingle()).WorkstationType;
        }
예제 #5
0
        void ImportData(string tempDir)
        {
            try
            {
                manifest = Deserialize <Manifest>(Path.Combine(tempDir, "Manifest"));

                data = Deserialize <Data>(Path.Combine(tempDir, "Data"));

                importRepo.PipeRepo.BeginTransaction();

                CheckWorkstationType(manifest.WorkstationType);

                CheckPortion(manifest.PortionID);

                Project project = ImportProject(data.Project);
                importedStation = project.WorkstationType;

                CheckProjectSequence(project, manifest.PortionNumber);
                if (!TaskIsCancelled)
                {
                    // imported elements count for messages
                    elements = elementsAll = data.Pipes.Count + data.Joints.Count + data.Components.Count;

                    IList <Pipe>      importedPipes      = ImportPipes(manifest, data.Pipes, tempDir);
                    IList <Joint>     importedJoints     = ImportJoints(manifest, data, tempDir);
                    IList <Component> importedComponents = ImportComponents(manifest, data, tempDir);

                    SavePortionInfo(manifest, importedPipes, importedJoints, importedComponents, project);
                }
                else
                {
                    tempDir = "";
                }
                importRepo.PipeRepo.Commit();
                TaskIsCancelled = false;
                progress        = 100;
                FireProgress(progress);
            }
            catch (RepositoryException ex)
            {
                log.Warn(this.GetType().Name + " | " + ex.ToString());
            }
        }
예제 #6
0
        // принимает на вход массив (закодированный) байт и выдает список кадров в виде списка байтовых массивов
        public static List <byte[]> GetFrame(WorkstationType sender, WorkstationType recipient, byte[] data)
        {
            int blockSize = 1024;

            byte[]        dataBlockSize = BitConverter.GetBytes(blockSize);
            int           pos           = 0;
            List <byte[]> frameList     = new List <byte[]>();

            while (data.Length > pos)
            {
                byte[] newFrame;
                if (data.Length / blockSize == 0)
                {
                    newFrame = new byte[data.Length % blockSize + 9];
                }
                else
                {
                    newFrame = new byte[1024];
                }
                newFrame[0] = (byte)Limiter.start;
                newFrame[1] = (byte)FieldType.data;
                newFrame[2] = (byte)sender;
                newFrame[3] = (byte)recipient;
                if (data.Length - pos >= blockSize)
                {
                    Array.Copy(dataBlockSize, 0, newFrame, 4, 4);
                    Array.Copy(data, pos, newFrame, 8, 1024);
                    newFrame[1028] = (byte)Limiter.stop;
                }
                else
                {
                    int lowerBlockSize = data.Length % blockSize;
                    Array.Copy(BitConverter.GetBytes(lowerBlockSize), 0, newFrame, 4, 4);
                    Array.Copy(data, pos, newFrame, 8, lowerBlockSize);
                    newFrame[3 + lowerBlockSize] = (byte)Limiter.stop;
                }

                frameList.Add(newFrame);
                pos += 1024;
            }
            return(frameList);
        }
예제 #7
0
        protected void WriteManifest(string tempDir, Guid portionId, int portionNumber, DateTime exportDateTime, WorkstationType workstationType)
        {
            Manifest manifest = new Manifest();

            manifest.ExportDateTime  = exportDateTime;
            manifest.PortionID       = portionId;
            manifest.PortionNumber   = portionNumber;
            manifest.WorkstationType = workstationType;

            XmlSerializer serializer = new XmlSerializer(typeof(Manifest));

            byte[] rawData;
            byte[] encryptedData;
            using (FileStream dataStream = new FileStream(Path.Combine(tempDir, "Manifest"), FileMode.CreateNew))
            {
                StringWriter sw     = new StringWriter();
                XmlWriter    writer = XmlWriter.Create(sw);
                serializer.Serialize(sw, manifest);

                rawData       = Encoding.Unicode.GetBytes(sw.ToString());
                encryptedData = encryptor.Encrypt(rawData, "^PRIZM_ENCRYPTION_KEY$");

                dataStream.Write(encryptedData, 0, encryptedData.Length);
            }

            System.IO.File.WriteAllText(Path.Combine(tempDir, "Manifest.sha1"), hasher.GetHash(encryptedData));
        }
 partial void OnWorkstationTypeChanging(WorkstationType value);
예제 #9
0
        /// <summary>
        /// if no project settings available, it will be created if user enters all necessary data
        /// </summary>
        /// <returns>status if project settings were created</returns>
        private static bool CreateProject()
        {
            bool result = false;
            IProjectRepository repo = (IProjectRepository)Program.Kernel.Get(typeof(IProjectRepository));

            Domain.Entity.Project pj = repo.GetSingle();

            if (pj == null)
            {
                using (var setupDialog = (FirstSetupXtraForm)Program.Kernel.Get(typeof(FirstSetupXtraForm)))
                {
                    setupDialog.ShowDialog();
                    if (setupDialog.DialogResult == DialogResult.Cancel)
                    {
                        System.Environment.Exit(0);
                    }
                    pj = repo.GetSingle();
                    if (pj == null)
                    {
                        ApplicationException e = new ApplicationException("Could not find project settings");
                        log.Error(e.Message);
                        throw e;
                    }
                }
            }
            else
            {
                result = true;
            }
            workstationType = pj.WorkstationType;
            log.Info("Project data has been " + (result ? "created" : "retrieved"));
            return result;
        }
예제 #10
0
 public byte[] GetOpenfileFrame(WorkstationType sender, WorkstationType recipient)
 {
     return(new byte[] { (byte)Limiter.start, (byte)FieldType.openfile, (byte)sender, (byte)recipient, (byte)Limiter.stop });
 }
예제 #11
0
 public byte[] GetUnlinkFrame(WorkstationType sender, WorkstationType recipient)
 {
     return(new byte[] { (byte)Limiter.start, (byte)FieldType.unlink, (byte)sender, (byte)recipient, (byte)Limiter.stop });
 }