public TypescriptDefaultFileMetaData(
     OverwriteBehaviour overwriteBehaviour,
     string codeGenType,
     string fileName,
     string fileExtension,
     string defaultLocationInProject,
     string className,
     string @namespace,
     string dependsUpon = null
     )
     : base(overwriteBehaviour: overwriteBehaviour,
            codeGenType: codeGenType,
            fileName: fileName,
            fileExtension: fileExtension,
            defaultLocationInProject: defaultLocationInProject)
 {
     if (!string.IsNullOrWhiteSpace(className))
     {
         this.CustomMetaData["ClassName"] = className;
     }
     if (!string.IsNullOrWhiteSpace(@namespace))
     {
         this.CustomMetaData["Namespace"] = @namespace;
     }
     if (!string.IsNullOrWhiteSpace(dependsUpon))
     {
         this.CustomMetaData["Depends On"] = dependsUpon;
     }
 }
 public BasicFileMetaData(
     string fileName,
     string fileExtension,
     OverwriteBehaviour overwriteBehaviour,
     string codeGenType,
     string fullLocationPath,
     string relativeFilePath,
     string defaultLocationInProject,
     string dependsUpon
     )
 {
     DefaultLocationInProject = defaultLocationInProject;
     DependsUpon = dependsUpon;
     if (fileExtension.StartsWith("."))
     {
         FileExtension = fileExtension.Substring(1);
     }
     else
     {
         FileExtension = fileExtension;
     }
     FileName           = fileName;
     CodeGenType        = codeGenType;
     OverwriteBehaviour = overwriteBehaviour;
     FullLocationPath   = fullLocationPath;
     RelativeFilePath   = relativeFilePath;
     CustomMetaData     = new Dictionary <string, string>();
 }
Example #3
0
        private static void RunTool(Options o)
        {
            if (!o.Copy && !o.Move)
            {
                Console.Error.WriteLine("One of either --copy or --move must be specified.");
                Environment.Exit(0);
            }
            if (o.Move)
            {
                Console.Error.WriteLine("--move is not yet implemented.");
                Environment.Exit(0);
            }
            string[] allClPaths = o.Paths.ToArray();
            foreach (string str in allClPaths)
            {
                Console.Error.WriteLine(str);
            }
            IEnumerable <string> clInputPaths = allClPaths.Take(allClPaths.Length - 1);
            string clOutputPath             = allClPaths.Last();
            IEnumerable <string> inputFiles = GetInputFilesFromInputPaths(clInputPaths);

            FileProcessor      processor      = new FileProcessor(new ModificationDateExtractor());
            OverwriteBehaviour overwrite      = o.Force ? OverwriteBehaviour.Permit : OverwriteBehaviour.Error;
            Action <string>    feedbackMethod = o.Quiet ? (Action <string>)null : PrintFeedback;

            foreach (string fn in inputFiles)
            {
                processor.Process(Verb.Copy, fn, clOutputPath, overwrite, feedbackMethod);
            }
        }
        /// <summary>
        /// Sets the C# file configuration
        /// </summary>
        public CSharpFileConfig(
            string className,
            string @namespace,
            string relativeLocation = "",
            OverwriteBehaviour overwriteBehaviour = OverwriteBehaviour.Always,
            string fileName      = null,
            string fileExtension = "cs",
            string dependsUpon   = null)
            : base(fileName ?? className, fileExtension, relativeLocation, overwriteBehaviour, "RoslynWeave")
        {
            CustomMetadata["ClassName"] = className ?? throw new ArgumentNullException(nameof(className));

            if (!string.IsNullOrWhiteSpace(@namespace))
            {
                CustomMetadata["Namespace"] = @namespace;
            }

            if (!string.IsNullOrWhiteSpace(dependsUpon))
            {
                CustomMetadata["Depends On"] = dependsUpon;
            }

            AutoFormat = true;
            ApplyNamespaceFormatting = true;
        }
        public RoslynDefaultFileMetaData(
            OverwriteBehaviour overwriteBehaviour,
            string fileName,
            string fileExtension,
            string defaultLocationInProject,
            string className,
            string @namespace,
            string dependsUpon = null
            )
            : base(overwriteBehaviour, SoftwareFactory.Templates.CodeGenType.RoslynWeave, fileName, fileExtension, defaultLocationInProject)
        {
            if (!string.IsNullOrWhiteSpace(className))
            {
                this.CustomMetaData["ClassName"] = className;
            }
            if (!string.IsNullOrWhiteSpace(@namespace))
            {
                this.CustomMetaData["Namespace"] = @namespace;
            }
            if (!string.IsNullOrWhiteSpace(dependsUpon))
            {
                this.CustomMetaData["Depends On"] = dependsUpon;

                /*
                 * if (!string.IsNullOrWhiteSpace(defaultLocationInProject))
                 * {
                 *  this.CustomMetaData["Depends On"] = defaultLocationInProject + "/" + dependsUpon;
                 * }
                 * else
                 * {
                 *  this.CustomMetaData["Depends On"] = dependsUpon;
                 * }*/
            }
        }
 public RoslynDefaultFileMetaData(
     OverwriteBehaviour overwriteBehaviour,
     string fileName,
     string fileExtension,
     string defaultLocationInProject
     )
     : this(overwriteBehaviour, fileName, fileExtension, defaultLocationInProject, null, null, null)
 {
     this.CustomMetaData["Namespace"] = "${Project.ProjectName}";
 }
Example #7
0
        public void Process(Verb verb, string inputPath, string baseOutputPath, OverwriteBehaviour overwriteBehaviour, Action <string> feedback)
        {
            DateTime fileDateTime = _dateExtractor.GetDate(inputPath);
            string   fileName     = Path.GetFileName(inputPath);
            string   outputFolder = Path.Combine(baseOutputPath, PathGenerator.GetPath(fileDateTime));

            Directory.CreateDirectory(outputFolder);
            string outputPath = Path.Combine(outputFolder, fileName);

            File.Copy(inputPath, outputPath, overwriteBehaviour == OverwriteBehaviour.Permit);
            feedback?.Invoke($"Copied {fileName} to {outputFolder}");
        }
Example #8
0
 public HtmlFileConfig(
     string fileName,
     string relativeLocation,
     OverwriteBehaviour overwriteBehaviour = OverwriteBehaviour.Always,
     string codeGenType   = Common.CodeGenType.Basic,
     string fileExtension = "html"
     ) : base(overwriteBehaviour: overwriteBehaviour,
              codeGenType: codeGenType,
              fileName: fileName,
              fileExtension: fileExtension,
              relativeLocation: relativeLocation)
 {
 }
 public SolutionFileMetaData(
     string outputType,
     OverwriteBehaviour overwriteBehaviour,
     string codeGenType,
     string fileName,
     string fileLocation)
 {
     _fileLocation      = fileLocation;
     OutputType         = outputType;
     OverwriteBehaviour = overwriteBehaviour;
     FileName           = fileName;
     CodeGenType        = codeGenType;
     CustomMetaData     = new Dictionary <string, string>();
 }
 public SqlFileConfig(
     OverwriteBehaviour overwriteBehaviour,
     string fileName,
     string relativeLocation,
     string fileExtension = "sql",
     string codeGenType   = Common.CodeGenType.Basic
     )
     : base(overwriteBehaviour: overwriteBehaviour,
            codeGenType: codeGenType,
            fileName: fileName,
            fileExtension: fileExtension,
            relativeLocation: relativeLocation)
 {
 }
 public TemplateFileConfig(
     string fileName,
     string fileExtension,
     string relativeLocation = "",
     OverwriteBehaviour overwriteBehaviour = OverwriteBehaviour.Always,
     string codeGenType = Common.CodeGenType.Basic
     )
 {
     CustomMetadata     = new Dictionary <string, string>();
     CodeGenType        = codeGenType;
     OverwriteBehaviour = overwriteBehaviour;
     FileName           = fileName;
     FileExtension      = fileExtension;
     LocationInProject  = relativeLocation;
 }
Example #12
0
 public TypeScriptFileConfig(
     string className,
     string fileName         = null,
     string relativeLocation = "",
     OverwriteBehaviour overwriteBehaviour = OverwriteBehaviour.Always,
     string codeGenType   = Common.CodeGenType.Basic,
     string fileExtension = "ts",
     string @namespace    = null
     ) : base(fileName: fileName ?? className.ToKebabCase(),
              fileExtension: fileExtension,
              relativeLocation: relativeLocation,
              overwriteBehaviour: overwriteBehaviour,
              codeGenType: codeGenType)
 {
     if (!string.IsNullOrWhiteSpace(className))
     {
         this.CustomMetadata["ClassName"] = className;
     }
     if (!string.IsNullOrWhiteSpace(@namespace))
     {
         this.CustomMetadata["Namespace"] = @namespace;
     }
 }
 public JavaFileConfig(
     string className,
     string package,
     string relativeLocation = "",
     string fileName         = null,
     OverwriteBehaviour overwriteBehaviour = OverwriteBehaviour.Always,
     string codeGenType   = Common.CodeGenType.Basic,
     string fileExtension = "java"
     )
     : base(overwriteBehaviour: overwriteBehaviour,
            codeGenType: codeGenType,
            fileName: fileName ?? className,
            fileExtension: fileExtension,
            relativeLocation: relativeLocation)
 {
     if (!string.IsNullOrWhiteSpace(className))
     {
         this.CustomMetadata["ClassName"] = className;
     }
     if (!string.IsNullOrWhiteSpace(package))
     {
         this.CustomMetadata["Package"] = package;
     }
 }
Example #14
0
        public async Task <ActionResult> Upload(HttpPostedFileBase[] files, OverwriteBehaviour overwriteBehaviour, string clientId)
        {
            SignalRMessage signalR = new SignalRMessage(clientId);

            supportedFolders.Add("WindowsAutopilotDeploymentProfile");
            supportedFolders.Add("DeviceConfiguration");
            supportedFolders.Add("DeviceCompliancePolicy");
            supportedFolders.Add("DeviceManagementScript");
            supportedFolders.Add("ManagedAppPolicy");
            supportedFolders.Add("RoleDefinition");

            try
            {
                GraphIntuneImport graphIntuneImport = new GraphIntuneImport(clientId, overwriteBehaviour);

                if (files.Length > 0 && files[0].FileName.Contains(".json"))
                {
                    foreach (HttpPostedFileBase file in files)
                    {
                        try
                        {
                            BinaryReader b       = new BinaryReader(file.InputStream);
                            byte[]       binData = b.ReadBytes(file.ContentLength);
                            string       result  = Encoding.UTF8.GetString(binData);
                            await graphIntuneImport.AddIntuneConfig(result);
                        }
                        catch (Exception e)
                        {
                            signalR.sendMessage("Error: " + e.Message);
                        }
                    }
                }
                else if (files.Length > 0 && files[0].FileName.Contains(".zip"))
                {
                    try
                    {
                        Dictionary <string, string> importFiles = new Dictionary <string, string>();
                        MemoryStream target = new MemoryStream();
                        files[0].InputStream.CopyTo(target);
                        byte[] data = target.ToArray();

                        using (var zippedStream = new MemoryStream(data))
                        {
                            using (var archive = new ZipArchive(zippedStream))
                            {
                                foreach (var entry in archive.Entries)
                                {
                                    try
                                    {
                                        if (entry != null)
                                        {
                                            using (var unzippedEntryStream = entry.Open())
                                            {
                                                using (var ms = new MemoryStream())
                                                {
                                                    unzippedEntryStream.CopyTo(ms);
                                                    var    unzippedArray = ms.ToArray();
                                                    string result        = Encoding.UTF8.GetString(unzippedArray);

                                                    if (!string.IsNullOrEmpty(result))
                                                    {
                                                        // Check if key exists
                                                        // Only the case because of enrollment restrictions coming with no value
                                                        if (importFiles.ContainsKey(entry.FullName))
                                                        {
                                                            Random r = new Random();
                                                            importFiles.Add(entry.FullName + r.Next(), result);
                                                        }
                                                        else
                                                        {
                                                            importFiles.Add(entry.FullName, result);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        signalR.sendMessage("Error: " + e.Message);
                                    }
                                }
                            }
                        }

                        // First create all scope tags
                        foreach (KeyValuePair <string, string> entry in importFiles)
                        {
                            if (entry.Key.Contains("RoleScopeTags"))
                            {
                                await graphIntuneImport.AddIntuneScopeTag(entry.Value);
                            }
                        }

                        // Process all remaining intune objects
                        foreach (KeyValuePair <string, string> entry in importFiles)
                        {
                            // Verify folder name
                            if (supportedFolders.Contains(entry.Key.Split('\\')[0]))
                            {
                                await graphIntuneImport.AddIntuneConfig(entry.Value);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        signalR.sendMessage("Error: " + e.Message);
                    }
                }
                else if (files.Length > 0)
                {
                    signalR.sendMessage("Error unsupported file: " + files[0].FileName);
                }
            }
            catch (Exception e)
            {
                signalR.sendMessage("Error: " + e.Message);
            }

            signalR.sendMessage("Done#!");
            return(new HttpStatusCodeResult(204));
        }
Example #15
0
        public async System.Threading.Tasks.Task <ActionResult> Upload(HttpPostedFileBase[] files, OverwriteBehaviour overwriteBehaviour, string clientId)
        {
            SignalRMessage signalR = new SignalRMessage(clientId);

            try
            {
                GraphIntuneImport graphIntuneImport = new GraphIntuneImport(clientId, overwriteBehaviour);

                if (files.Length > 0 && files[0].FileName.Contains(".json"))
                {
                    foreach (HttpPostedFileBase file in files)
                    {
                        try
                        {
                            BinaryReader b       = new BinaryReader(file.InputStream);
                            byte[]       binData = b.ReadBytes(file.ContentLength);
                            string       result  = Encoding.UTF8.GetString(binData);
                            await graphIntuneImport.AddIntuneConfig(result);
                        }
                        catch (Exception e)
                        {
                            signalR.sendMessage("Error: " + e.Message);
                        }
                    }
                }
                else if (files.Length > 0 && files[0].FileName.Contains(".zip"))
                {
                    try
                    {
                        MemoryStream target = new MemoryStream();
                        files[0].InputStream.CopyTo(target);
                        byte[] data = target.ToArray();

                        using (var zippedStream = new MemoryStream(data))
                        {
                            using (var archive = new ZipArchive(zippedStream))
                            {
                                foreach (var entry in archive.Entries)
                                {
                                    try
                                    {
                                        if (entry != null)
                                        {
                                            if (entry.FullName.Contains("WindowsAutopilotDeploymentProfile") || entry.FullName.Contains("DeviceConfiguration") || entry.FullName.Contains("DeviceCompliancePolicy") || entry.FullName.Contains("DeviceManagementScript") || entry.FullName.Contains("ManagedAppPolicy"))
                                            {
                                                using (var unzippedEntryStream = entry.Open())
                                                {
                                                    using (var ms = new MemoryStream())
                                                    {
                                                        unzippedEntryStream.CopyTo(ms);
                                                        var    unzippedArray = ms.ToArray();
                                                        string result        = Encoding.UTF8.GetString(unzippedArray);

                                                        if (!string.IsNullOrEmpty(result))
                                                        {
                                                            await graphIntuneImport.AddIntuneConfig(result);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        signalR.sendMessage("Error: " + e.Message);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        signalR.sendMessage("Error: " + e.Message);
                    }
                }
                else if (files.Length > 0)
                {
                    signalR.sendMessage("Error unsupported file: " + files[0].FileName);
                }
            }
            catch (Exception e)
            {
                signalR.sendMessage("Error: " + e.Message);
            }

            signalR.sendMessage("Done#!");
            return(new HttpStatusCodeResult(204));
        }
Example #16
0
        public async Task <ActionResult> Upload(HttpPostedFileBase[] files, OverwriteBehaviour overwriteBehaviour, string clientId)
        {
            SignalRMessage signalRMessage = new SignalRMessage(clientId);

            try
            {
                GraphConditionalAccess graphConditionalAccess = new GraphConditionalAccess(clientId);
                IEnumerable <ConditionalAccessPolicy> conditionalAccessPolicies = await graphConditionalAccess.GetConditionalAccessPoliciesAsync();

                List <string> uploadedConditionalAccessPolicies = new List <string>();

                if (files.Length > 0 && files[0].FileName.Contains(".json"))
                {
                    foreach (HttpPostedFileBase file in files)
                    {
                        BinaryReader binaryReader = new BinaryReader(file.InputStream);
                        byte[]       binData      = binaryReader.ReadBytes(file.ContentLength);
                        uploadedConditionalAccessPolicies.Add(Encoding.UTF8.GetString(binData));
                    }
                }
                else if (files.Length > 0 && files[0].FileName.Contains(".zip"))
                {
                    try
                    {
                        MemoryStream target = new MemoryStream();
                        files[0].InputStream.CopyTo(target);
                        byte[] data = target.ToArray();

                        using (var zippedStream = new MemoryStream(data))
                        {
                            using (var archive = new ZipArchive(zippedStream))
                            {
                                foreach (var entry in archive.Entries)
                                {
                                    try
                                    {
                                        if (entry != null)
                                        {
                                            using (var unzippedEntryStream = entry.Open())
                                            {
                                                using (var ms = new MemoryStream())
                                                {
                                                    unzippedEntryStream.CopyTo(ms);
                                                    var unzippedArray = ms.ToArray();
                                                    uploadedConditionalAccessPolicies.Add(Encoding.UTF8.GetString(unzippedArray));
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        signalRMessage.sendMessage("Error: " + e.Message);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        signalRMessage.sendMessage("Error: " + e.Message);
                    }
                }

                foreach (string uploadedPolicy in uploadedConditionalAccessPolicies)
                {
                    ConditionalAccessPolicy conditionalAccessPolicy = JsonConvert.DeserializeObject <ConditionalAccessPolicy>(uploadedPolicy);

                    switch (overwriteBehaviour)
                    {
                    case OverwriteBehaviour.DISCARD:
                        // Check for any policy with same name or id
                        if (conditionalAccessPolicies.All(p => !p.id.Contains(conditionalAccessPolicy.id) && conditionalAccessPolicies.All(policy => !policy.displayName.Equals(conditionalAccessPolicy.displayName))))
                        {
                            var response = await graphConditionalAccess.TryAddConditionalAccessPolicyAsync(conditionalAccessPolicy);
                        }
                        else
                        {
                            if (conditionalAccessPolicies.Any(p => p.id.Contains(conditionalAccessPolicy.id)))
                            {
                                signalRMessage.sendMessage($"Discarding Policy '{conditionalAccessPolicy.displayName}' ({conditionalAccessPolicy.id}) already exists!");
                            }
                            else
                            {
                                signalRMessage.sendMessage($"Discarding Policy '{conditionalAccessPolicy.displayName}' - policy with this name already exists!");
                            }
                        }
                        break;

                    case OverwriteBehaviour.IMPORT_AS_DUPLICATE:
                        await graphConditionalAccess.TryAddConditionalAccessPolicyAsync(conditionalAccessPolicy);

                        break;

                    case OverwriteBehaviour.OVERWRITE_BY_ID:

                        // match by object ID
                        if (conditionalAccessPolicies.Any(policy => policy.id.Equals(conditionalAccessPolicy.id)))
                        {
                            await graphConditionalAccess.PatchConditionalAccessPolicyAsync(conditionalAccessPolicy);
                        }
                        // Create a new policy
                        else
                        {
                            var result = await graphConditionalAccess.TryAddConditionalAccessPolicyAsync(conditionalAccessPolicy);
                        }
                        break;

                    case OverwriteBehaviour.OVERWRITE_BY_NAME:
                        if (conditionalAccessPolicies.Any(policy => policy.displayName.Equals(conditionalAccessPolicy.displayName)))
                        {
                            string replaceObjectId = conditionalAccessPolicies.Where(policy => policy.displayName.Equals(conditionalAccessPolicy.displayName)).Select(policy => policy.id).First();
                            conditionalAccessPolicy.id = replaceObjectId;
                            await graphConditionalAccess.PatchConditionalAccessPolicyAsync(conditionalAccessPolicy);
                        }
                        else
                        {
                            var result = await graphConditionalAccess.TryAddConditionalAccessPolicyAsync(conditionalAccessPolicy);
                        }

                        break;
                    }
                }
            }
            catch (Exception e)
            {
                signalRMessage.sendMessage("Error: " + e.Message);
            }

            signalRMessage.sendMessage("Done#!");
            return(new HttpStatusCodeResult(204));
        }