BLL.Workflows.Multicast.GenerateProcessArguments C# (CSharp) Метод

GenerateProcessArguments() приватный Метод

private GenerateProcessArguments ( ) : string
Результат string
        private string GenerateProcessArguments()
        {
            var isUnix = Environment.OSVersion.ToString().Contains("Unix");

            var schema = new ClientPartitionHelper(_imageProfile).GetImageSchema();

            var schemaCounter = -1;
            var multicastHdCounter = 0;
            string processArguments = null;
            foreach (var hd in schema.HardDrives)
            {
                schemaCounter++;
                if (!hd.Active) continue;
                multicastHdCounter++;

                var imagePath = Settings.PrimaryStoragePath + "images" + Path.DirectorySeparatorChar +
                                _imageProfile.Image.Name + Path.DirectorySeparatorChar + "hd" +
                                schemaCounter;

                var x = 0;
                foreach (var part in schema.HardDrives[schemaCounter].Partitions)
                {
                    if (!part.Active) continue;
                    string imageFile = null;
                    foreach (var ext in new[] {".ntfs", ".fat", ".extfs", ".hfsp", ".imager", ".winpe", ".xfs"})
                    {
                        try
                        {
                            imageFile =
                         Directory.GetFiles(
                             imagePath + Path.DirectorySeparatorChar, "part" + part.Number + ext + ".*")
                             .FirstOrDefault();
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(ex.Message);
                            return null;

                        }

                        if (imageFile != null) break;

                        //Look for lvm
                        if (part.VolumeGroup == null) continue;
                        if (part.VolumeGroup.LogicalVolumes == null) continue;
                        foreach (var lv in part.VolumeGroup.LogicalVolumes.Where(lv => lv.Active))
                        {
                            try
                            {
                                imageFile =
                             Directory.GetFiles(
                                 imagePath + imagePath + Path.DirectorySeparatorChar, lv.VolumeGroup + "-" +
                                                                                      lv.Name + ext + ".*")
                                 .FirstOrDefault();
                            }
                            catch (Exception ex)
                            {
                                Logger.Log(ex.Message);
                                return null;
                            }

                        }
                    }

                    if (imageFile == null)
                        continue;
                    if (_imageProfile.Image.Environment == "winpe" &&
                        schema.HardDrives[schemaCounter].Table.ToLower() == "gpt")
                    {
                        if (part.Type.ToLower() == "system" || part.Type.ToLower() == "recovery" ||
                            part.Type.ToLower() == "reserved")
                            continue;
                    }
                    if (_imageProfile.Image.Environment == "winpe" &&
                        schema.HardDrives[schemaCounter].Table.ToLower() == "mbr")
                    {
                        if (part.Number == schema.HardDrives[schemaCounter].Boot && schema.HardDrives[schemaCounter].Partitions.Length > 1)
                            continue;
                    }
                    x++;

                    string minReceivers;
                    string senderArgs;
                    if (_isOnDemand)
                    {
                        senderArgs = Settings.SenderArgs;
                        if (!string.IsNullOrEmpty(_clientCount))
                            minReceivers = " --min-receivers " + _clientCount;
                        else
                            minReceivers = "";
                    }
                    else
                    {
                        senderArgs = string.IsNullOrEmpty(_imageProfile.SenderArguments)
                            ? Settings.SenderArgs
                            : _imageProfile.SenderArguments;
                        minReceivers = " --min-receivers " + _computers.Count;
                    }

                    string compAlg;
                    string stdout = "";
                    switch (Path.GetExtension(imageFile))
                    {
                        case ".lz4":
                            compAlg = isUnix ? "lz4 -d " : "lz4.exe\" -d ";
                            stdout = " - ";
                            break;
                        case ".gz":
                            compAlg = isUnix ? "gzip -c -d " : "gzip.exe\" -c -d ";
                            stdout = "";
                            break;
                        case ".uncp":
                            compAlg = "none";
                            break;
                        case ".wim":
                            compAlg = "none";
                            break;
                        default:
                            return null;
                    }

                    if (isUnix)
                    {
                        string prefix = null;
                        if(multicastHdCounter == 1)
                            prefix = x == 1 ? " -c \"" : " ; ";
                        else
                            prefix = " ; ";

                        if (compAlg == "none" || Settings.MulticastDecompression == "client")
                        {
                            processArguments += (prefix + "cat " + "\"" + imageFile + "\"" + " | udp-sender" +
                                                 " --portbase " + _multicastSession.Port + minReceivers + " " +
                                                 " --ttl 32 " +
                                                 senderArgs);
                        }

                        else
                        {
                            processArguments += (prefix + compAlg + "\"" + imageFile + "\"" + stdout + " | udp-sender" +
                                                 " --portbase " + _multicastSession.Port + minReceivers + " " +
                                                 " --ttl 32 " +
                                                 senderArgs);
                        }
                    }
                    else
                    {
                        var appPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "private" +
                                      Path.DirectorySeparatorChar + "apps" + Path.DirectorySeparatorChar;

                        string prefix = null;
                        if (multicastHdCounter == 1)
                            prefix = x == 1 ? " /c \"" : " & ";
                        else
                            prefix = " & ";

                        if (compAlg == "none" || Settings.MulticastDecompression == "client")
                        {
                            processArguments += (prefix + "\"" + appPath +
                                                 "udp-sender.exe" + "\"" + " --file " + "\"" + imageFile + "\"" +
                                                 " --portbase " + _multicastSession.Port + minReceivers + " " +
                                                 " --ttl 32 " +
                                                 senderArgs);
                        }
                        else
                        {
                            processArguments += (prefix + "\"" + appPath + compAlg + "\"" + imageFile + "\"" + stdout + " | " + "\"" + appPath +
                                                 "udp-sender.exe" + "\"" +
                                                 " --portbase " + _multicastSession.Port + minReceivers + " " +
                                                 " --ttl 32 " +
                                                 senderArgs);
                        }

                    }
                }
            }

            processArguments += "\"";
            return processArguments;
        }