Пример #1
0
        private void GetFunctionCode(string copyFromFunctionName, out string markupTemplate, out string code)
        {
            IFunction function = FunctionFacade.GetFunction(copyFromFunctionName);

            if (function is FunctionWrapper)
            {
                function = (function as FunctionWrapper).InnerFunction;
            }

            var    razorFunction = (UserControlBasedFunction)function;
            string filePath      = PathUtil.Resolve(razorFunction.VirtualPath);
            string codeFilePath  = filePath + ".cs";

            Verify.That(C1File.Exists(codeFilePath), "Codebehind file not found: {0}", codeFilePath);

            markupTemplate = C1File.ReadAllText(filePath);
            code           = C1File.ReadAllText(codeFilePath);

            const string quote             = "\"";
            string       codeFileReference = quote + Path.GetFileName(codeFilePath) + quote;

            int codeReferenceOffset = markupTemplate.IndexOf(codeFileReference, StringComparison.OrdinalIgnoreCase);

            Verify.That(codeReferenceOffset > 0, "Failed to find codebehind file reference '{0}'".FormatWith(codeFileReference));

            markupTemplate = markupTemplate.Replace(codeFileReference,
                                                    quote + Marker_CodeFile + quote,
                                                    StringComparison.OrdinalIgnoreCase);
        }
Пример #2
0
        /// <exclude />
        public static string GetFunctionCode(this IInlineFunction function)
        {
            string filepath = GetSourceFilePath(function);

            // Making 5 attempts to read the file
            for (int i = 5; i > 0; i--)
            {
                try
                {
                    return(C1File.ReadAllText(filepath));
                }
                catch (FileNotFoundException)
                {
                    throw;
                }
                catch (IOException)
                {
                    if (i == 1)
                    {
                        throw;
                    }

                    Thread.Sleep(100);
                }
            }
            throw new InvalidOperationException("This line should not be reachable");
        }
Пример #3
0
        private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            string path = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.TreeDefinitionsDirectory), this.Filename);

            this.Bindings.Add("TreeId", Path.GetFileNameWithoutExtension(this.Filename));
            this.Bindings.Add("TreeDefinitionMarkup", C1File.ReadAllText(path));
        }
        private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            string markup;

            if (C1File.Exists(this.FilePath))
            {
                markup = C1File.ReadAllText(this.FilePath);
            }
            else
            {
                // someone deleted the feature file, but that won't stop us!
                XhtmlDocument template = new XhtmlDocument();
                template.Head.Add("");
                template.Body.Add("");
                markup = template.ToString();
            }

            this.Bindings.Add("FeatureName", this.FeatureName);
            this.Bindings.Add("Markup", markup);

            if (Path.GetExtension(this.FilePath) == ".html")
            {
                this.documentFormActivity1.FormDefinitionFileName = @"\Administrative\PageTemplateFeature\EditVisual.xml";
            }
            else
            {
                this.documentFormActivity1.FormDefinitionFileName = @"\Administrative\PageTemplateFeature\EditMarkup.xml";
            }
        }
        private void ParseExistingTemplateForCopying(Guid templateId, out string codeTemplate, out string folderPath)
        {
            var razorTemplate = PageTemplateFacade.GetPageTemplate(templateId) as RazorPageTemplateDescriptor;

            Verify.IsNotNull(razorTemplate, "Failed to get razor template descriptor by id '{0}'", templateId);

            var provider = PageTemplateProviderRegistry.GetProviderByTemplateId(templateId) as RazorPageTemplateProvider;

            Verify.IsNotNull(provider, "Failed to get razor template provider by template id '{0}'", templateId);

            string fullPath = PathUtil.Resolve(razorTemplate.VirtualPath);
            string text     = C1File.ReadAllText(fullPath);



            const string quote = @"""";

            Verify.That(text.IndexOf(templateId.ToString(), StringComparison.OrdinalIgnoreCase) > 0,
                        "Failed to replace existing templateId '{0}'", templateId);

            text = text.Replace(templateId.ToString(), Marker_TemplateId, StringComparison.OrdinalIgnoreCase);

            // Replacing title
            text = text.Replace("@" + quote + razorTemplate.Title.Replace(quote, quote + quote) + quote,
                                quote + Marker_TemplateTitle + quote)
                   .Replace(quote + CSharpEncodeString(razorTemplate.Title) + quote,
                            quote + Marker_TemplateTitle + quote);

            codeTemplate = text;
            folderPath   = Path.GetDirectoryName(fullPath);
        }
Пример #6
0
        public virtual string GenerateNextOrderId(OrderCreationSettings settings)
        {
            int orderId;

            lock (Lock)
            {
                var content = C1File.ReadAllText(LastUsedOrderIdFile);
                int.TryParse(content, out orderId);

                orderId = orderId + 1;

                C1File.WriteAllText(LastUsedOrderIdFile, orderId.ToString(CultureInfo.InvariantCulture));
            }

            string sOrderId;

            if (settings.MinimumOrderIdLength > 0)
            {
                var format = "D" + settings.MinimumOrderIdLength;

                sOrderId = orderId.ToString(format, CultureInfo.InvariantCulture);
            }
            else
            {
                sOrderId = orderId.ToString(CultureInfo.InvariantCulture);
            }

            if (!String.IsNullOrEmpty(settings.OrderIdPrefix))
            {
                sOrderId = settings.OrderIdPrefix + sOrderId;
            }

            if (ECommerce.IsTestMode)
            {
                var hashMachineName = Environment.MachineName.GetHashCode().ToString(CultureInfo.InvariantCulture);
                if (hashMachineName.StartsWith("-"))
                {
                    hashMachineName = hashMachineName.Remove(0, 1);
                }

                var maxMachineNameLength = 20 - 6 - sOrderId.Length;
                if (hashMachineName.Length > maxMachineNameLength)
                {
                    hashMachineName = hashMachineName.Substring(0, maxMachineNameLength);
                }

                sOrderId = String.Format("TEST-{0}-{1}", hashMachineName, sOrderId);
            }

            sOrderId = sOrderId.Trim();

            return(sOrderId);
        }
Пример #7
0
        /// <summary>
        /// Renders a url and return a full path to a rendered image, or <value>null</value> when rendering process is failing or inaccessible.
        /// </summary>
        public static async Task <RenderingResult> RenderUrlAsync(HttpContext context, string url, string mode)
        {
            string dropFolder = GetCacheFolder(mode);

            if (!C1Directory.Exists(dropFolder))
            {
                C1Directory.CreateDirectory(dropFolder);
            }
            string urlHash = Convert.ToBase64String(BitConverter.GetBytes(url.GetHashCode())).Substring(0, 6).Replace('+', '-').Replace('/', '_');

            string outputImageFileName = Path.Combine(dropFolder, urlHash + ".png");
            string outputFileName      = Path.Combine(dropFolder, urlHash + ".output");
            string errorFileName       = Path.Combine(dropFolder, urlHash + ".error");

            if (C1File.Exists(outputImageFileName) || C1File.Exists(outputFileName))
            {
#if BrowserRender_NoCache
                File.Delete(outputFileName);
#else
                string output = C1File.Exists(outputFileName) ? C1File.ReadAllText(outputFileName) : null;

                return(new RenderingResult {
                    FilePath = outputImageFileName, Output = output, Status = RenderingResultStatus.Success
                });
#endif
            }

            if (!Enabled)
            {
                return(null);
            }

            var result = await MakePreviewRequestAsync(context, url, outputImageFileName, mode);

            if (result.Status >= RenderingResultStatus.Error)
            {
                C1File.WriteAllText(errorFileName, result.Output);
            }

            if (!Enabled)
            {
                return(null);
            }

            if (result.Status == RenderingResultStatus.Success)
            {
                C1File.WriteAllText(outputFileName, result.Output);
            }

            return(result);
        }
        private string GetFunctionCode(string copyFromFunction)
        {
            IFunction function = FunctionFacade.GetFunction(copyFromFunction);

            if (function is FunctionWrapper)
            {
                function = (function as FunctionWrapper).InnerFunction;
            }

            var    razorFunction = (RazorBasedFunction)function;
            string filePath      = PathUtil.Resolve(razorFunction.VirtualPath);

            return(C1File.ReadAllText(filePath));
        }
Пример #9
0
        private bool TemplateIsClonable(MasterPagePageTemplateDescriptor templateDescriptor)
        {
            string codebehindFile = templateDescriptor.CodeBehindFilePath;

            if (codebehindFile == null)
            {
                return(false);
            }

            string masterFile = templateDescriptor.FilePath;

            string codebehindFileReference = "\"" + Path.GetFileName(codebehindFile) + "\"";
            string templateId = templateDescriptor.Id.ToString();

            return(C1File.ReadAllText(codebehindFile).IndexOf(templateId, StringComparison.OrdinalIgnoreCase) > 0 &&
                   C1File.ReadAllText(masterFile).IndexOf(codebehindFileReference, StringComparison.OrdinalIgnoreCase) > 0);
        }
        public static bool TryExtractTemplateIdFromCSharpCode(string filePath, out Guid templateId, string idTokenBegin, string idTokenEnd)
        {
            templateId = Guid.Empty;

            if (!C1File.Exists(filePath))
            {
                return(false);
            }

            var allText = C1File.ReadAllText(filePath, Encoding.UTF8);

            allText = RemoveWhiteSpaces(allText);

            string beginning = RemoveWhiteSpaces(idTokenBegin);
            string ending    = RemoveWhiteSpaces(idTokenEnd);

            int firstIndex = allText.IndexOf(beginning, StringComparison.Ordinal);

            if (firstIndex < 0)
            {
                return(false);
            }

            int lastIndex = allText.LastIndexOf(beginning, StringComparison.Ordinal);

            if (lastIndex != firstIndex)
            {
                return(false);
            }

            int endOffset = allText.IndexOf(ending, firstIndex, StringComparison.Ordinal);

            if (endOffset < 0)
            {
                return(false);
            }

            int    guidOffset = firstIndex + beginning.Length;
            string guidStr    = allText.Substring(guidOffset, endOffset - guidOffset);

            return(Guid.TryParse(guidStr, out templateId));
        }
Пример #11
0
        private void ParseTemplateForCopying(
            Guid templateId,
            out string markupTemplate,
            out string codebehindTemplate,
            out string templateFolder)
        {
            var masterTemplate = PageTemplateFacade.GetPageTemplate(templateId) as MasterPagePageTemplateDescriptor;

            Verify.IsNotNull(masterTemplate, "Failed to get MasterPagePageTemplateDescriptor by template id '{0}'", templateId);

            var provider = PageTemplateProviderRegistry.GetProviderByTemplateId(templateId) as MasterPagePageTemplateProvider;

            Verify.IsNotNull(provider, "Failed to get MasterPagePageTemplateProvider by template id '{0}'", templateId);

            string markup     = C1File.ReadAllText(masterTemplate.FilePath);
            string codebehind = C1File.ReadAllText(masterTemplate.CodeBehindFilePath);

            string codebehindFileName = Path.GetFileName(masterTemplate.CodeBehindFilePath);

            // Parsing markup
            markup = markup.Replace(codebehindFileName, Marker_Codebehind);

            // Parsing codebehind
            const string quote = @"""";

            Verify.That(codebehind.IndexOf(templateId.ToString(), StringComparison.OrdinalIgnoreCase) > 0,
                        "Failed to replace existing templateId '{0}'", templateId);

            codebehind = codebehind.Replace(templateId.ToString(), Marker_TemplateId, StringComparison.OrdinalIgnoreCase);

            // Replacing title, considering 2 types of encoding
            codebehind = codebehind.Replace("@" + quote + masterTemplate.Title.Replace(quote, quote + quote) + quote,
                                            quote + Marker_TemplateTitle + quote);
            codebehind = codebehind.Replace(quote + CSharpEncodeString(masterTemplate.Title) + quote,
                                            quote + Marker_TemplateTitle + quote);


            markupTemplate     = markup;
            codebehindTemplate = codebehind;
            templateFolder     = Path.GetDirectoryName(masterTemplate.CodeBehindFilePath);
        }
Пример #12
0
        /// <exclude />
        public static string MergeScripts(string type, IEnumerable <string> scriptFilenames, string folderPath, string targetPath)
        {
            string sourcesFilename = targetPath + "\\" + type + "-uncompressed.js";

            FileUtils.RemoveReadOnly(sourcesFilename);

            C1File.WriteAllText(sourcesFilename, string.Empty /* GetTimestampString() */);

            foreach (string scriptFilename in scriptFilenames)
            {
                string scriptPath = scriptFilename.Replace("${root}", folderPath).Replace("/", "\\");

                string lines = C1File.ReadAllText(scriptPath);


                C1File.AppendAllText(sourcesFilename, lines);
                C1File.AppendAllText(sourcesFilename, Environment.NewLine + Environment.NewLine);
            }

            return(sourcesFilename);
        }
Пример #13
0
    protected void Page_PreInit(object sender, EventArgs e)
    {
        var isCSSCompiled = C1File.Exists(this.MapPath("styles/styles.min.css")) && C1File.Exists(this.MapPath("styles/styles.css"));

        if (!isCSSCompiled)
        {
            contentHolder.Text = C1File.ReadAllText(this.MapPath(gruntHolderFileUrl));
            return;
        }

        string myPathAndQuery = Request.Url.PathAndQuery;

        if (!myPathAndQuery.Contains("/Composite/"))
        {
            // not launching in /Composite/ folder (case sensitive)! The wysiwyg editor support code URL handling does case sensitive searches, so we fix it right here. Tnx to the sucky string features in xslt 1.0
            int    badlyCaseIndex    = myPathAndQuery.IndexOf("/composite/", StringComparison.OrdinalIgnoreCase);
            string fixedPathAndQuery = string.Format("{0}/Composite/{1}",
                                                     myPathAndQuery.Substring(0, badlyCaseIndex),
                                                     myPathAndQuery.Substring(badlyCaseIndex + 11));

            Response.Redirect(fixedPathAndQuery);
        }

        if (SystemSetupFacade.IsSystemFirstTimeInitialized == false)
        {
            if (System.Web.HttpContext.Current.Request.UserAgent == null)
            {
                Response.Redirect("unknownbrowser.aspx");
                return;
            }
            contentHolder.Text = C1File.ReadAllText(MapPath(welcomeHolderFileUrl));
        }
        else
        {
            contentHolder.Text = C1File.ReadAllText(this.MapPath(loginHolderFileUrl));
        }
    }
Пример #14
0
 /// <exclude />
 public string ReadAllText()
 {
     return(C1File.ReadAllText(this.FullPath));
 }
Пример #15
0
 public static string LoadDefaultTemplateFile(string fileName)
 {
     return(C1File.ReadAllText(PathUtil.Resolve("~/Composite/templates/PageTemplates/" + fileName))
            .Replace("    ", "\t"));
 }