Ejemplo n.º 1
0
        public static void Send(MailMessage mail)
        {
            string securityProtocol = ConfiguracaoAppUtil.Get(enumConfiguracaoGeral.emailSecurityProtocol);

            if ((!string.IsNullOrEmpty(securityProtocol)) && (securityProtocol != "default"))
            {
                ServicePointManager.SecurityProtocol = EnumExtensions.FromString <SecurityProtocolType>(securityProtocol);
            }

            SmtpClient smtp = new SmtpClient();

            smtp.Host           = ConfiguracaoAppUtil.Get(enumConfiguracaoGeral.emailHost);
            smtp.Port           = ConfiguracaoAppUtil.GetAsInt(enumConfiguracaoGeral.emailPort);
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            if (string.IsNullOrWhiteSpace(ConfiguracaoAppUtil.Get(enumConfiguracaoGeral.emailUser)) || string.IsNullOrWhiteSpace(ConfiguracaoAppUtil.Get(enumConfiguracaoGeral.emailPass)))
            {
                smtp.UseDefaultCredentials = true;
            }
            else
            {
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new NetworkCredential(ConfiguracaoAppUtil.Get(enumConfiguracaoGeral.emailUser), ConfiguracaoAppUtil.Get(enumConfiguracaoGeral.emailPass));
            }
            smtp.EnableSsl = ConfiguracaoAppUtil.GetAsBool(enumConfiguracaoGeral.emailSSL);
            smtp.Send(mail);
        }
        protected virtual Column GetColumn(Item item)
        {
            Assert.ArgumentNotNull(item, "item");
            Column column = new Column
            {
                Title    = item["HeaderText"],
                Name     = string.IsNullOrEmpty(item["DataField"]) ? item.Name : item["DataField"],
                Sortable = (item["Sortable"] != null) && (item["Sortable"] == "1"),
                Key      = (item["Key"] != null) && (item["Key"] == "1"),
                Hidden   = (item["Hidden"] != null) && (item["Hidden"] == "1")
            };

            if (!string.IsNullOrEmpty(item["Alignment"]))
            {
                Item item2 = Sitecore.Context.Database.GetItem(item["Alignment"]);
                column.Alignment = (item2 != null) ? EnumExtensions.FromString <TextAlignment>(item2.Name, TextAlignment.Center) : TextAlignment.Center;
            }
            if (!string.IsNullOrEmpty(item["Formatter"]))
            {
                Item item3 = Sitecore.Context.Database.GetItem(item["Formatter"]);
                column.Formatter = (item3 != null) ? EnumExtensions.FromString <Formatter>(item3.Name, Formatter.None) : Formatter.None;
            }
            if (column.Key && !this.DetailListKeys.Contains(column.Name))
            {
                this.DetailListKeys.Add(column.Name);
            }
            this.ResolveColumnTemplate(column, item);
            return(column);
        }
        protected virtual void InitializeFilterBuilder()
        {
            Func <Item, FilterField> selector = null;

            this.filterBuidler.Attributes["UpdateControls"] = this.detailList.UniqueID;
            if (this.filterBuidler.EnableSearching && !this.filterBuidler.EnableFiltering)
            {
                if (selector == null)
                {
                    selector = i => this.GetFilterField(i);
                }
                this.filterBuidler.Fields.Add(this.DataSourceItem.Children.Where <Item>(delegate(Item i)
                {
                    if (!string.IsNullOrEmpty(i["Hidden"]))
                    {
                        return(!(i["Hidden"] == "1"));
                    }
                    return(true);
                }).Select <Item, FilterField>(selector));
            }
            else if (this.filterBuidler.EnableFiltering && !string.IsNullOrEmpty(this.DataSourceItem["Filters"]))
            {
                foreach (string str in this.DataSourceItem["Filters"].Split(new char[] { '|' }))
                {
                    Item item = Sitecore.Context.Database.GetItem(str);
                    if ((item != null) && item.HasChildren)
                    {
                        FilterField field = new FilterField
                        {
                            Title = string.IsNullOrEmpty(item["title"]) ? string.Empty : item["title"],
                            Name  = string.IsNullOrEmpty(item["name"]) ? string.Empty : item["name"]
                        };
                        field.Type  = EnumExtensions.FromString <FilterFieldType>(item["type"], FilterFieldType.Select);
                        field.Group = string.IsNullOrEmpty(item["title"]) ? string.Empty : item["title"];
                        foreach (Item item2 in item.Children)
                        {
                            Sitecore.Web.UI.WebControls.Expression expression = new Sitecore.Web.UI.WebControls.Expression
                            {
                                Title    = item2["title"],
                                Value    = item2["value"],
                                Operator = item2["operator"]
                            };
                            field.Expressions.Add(expression);
                        }
                        this.filterBuidler.Fields.Add(field);
                    }
                }
            }
        }
 protected virtual void InitializeDetailList()
 {
     if (this.DataSourceItem != null)
     {
         this.detailList.Columns.Add(this.DataSourceItem.Children.Select <Item, Column>(new Func <Item, Column>(this.GetColumn)));
         this.detailList.DataKeyNames = (from c in this.detailList.Columns
                                         where c.Key
                                         select c.Name).ToArray <string>();
         this.detailList.DataSourceID = this.dataSourceControl.ID;
         Item   item = Sitecore.Context.Database.GetItem(this.DataSourceItem["DefaultSortColumn"]);
         string str  = (item != null) ? item["DataField"] : string.Empty;
         string str2 = this.DataSourceItem["DefaultSortDirection"];
         if (!string.IsNullOrEmpty(str))
         {
             this.detailList.SortColumn    = str;
             this.detailList.SortDirection = EnumExtensions.FromString <SortDirection>(str2, SortDirection.Ascending);
         }
         this.detailList.LoadDataWith = EnumExtensions.FromString <LoadMode>(this.DataSourceItem["LoadDataWith"], LoadMode.PageScroll);
         if (this.detailList.LoadDataWith == LoadMode.ElementScroll)
         {
             int result = 6;
             if (int.TryParse(this.DataSourceItem["Rows"], out result))
             {
                 this.detailList.RowNum = result;
             }
         }
         bool flag = this.DataSourceItem["Multiselect"] == "1";
         this.detailList.Multiselect = flag;
         if (flag)
         {
             this.detailList.RowClicked          += new EventHandler <RowEventArgs>(this.DetailList_MultiRowClicked);
             this.detailList.SelectedRowsChanged += new EventHandler <EventArgs>(this.DetailList_MultiSelectedRowsChanged);
         }
         else
         {
             this.detailList.RowClicked          += new EventHandler <RowEventArgs>(this.DetailList_SingleRowClicked);
             this.detailList.SelectedRowsChanged += new EventHandler <EventArgs>(DetailList_SingleRowChanged);
         }
     }
 }
        /// <summary>
        /// Parte a file to object content
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private static FileContent ParseToFileContent(FileInfo file)
        {
            string Delimiter = "ç";

            FileContent content = new FileContent();

            string[] lines = PathUtil.ExtractInformation(file);

            #region Populate file content based on text file

            foreach (string line in lines)
            {
                //Split line based on rules
                var keys = line.Split(Delimiter);
                //Get classification
                ClassificatorEnum Type = EnumExtensions.FromString <ClassificatorEnum>(keys.FirstOrDefault());
                //Populate object
                Classificate(ref content, Type, keys);
            }
            #endregion

            return(content);
        }
Ejemplo n.º 6
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (sourceFile.StartsWith(@".\"))
            {
                sourceFile = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, sourceFile.Substring(2));
            }
            else
            {
                sourceFile = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, sourceFile);
            }

            sourceFile = System.IO.Path.GetFullPath(sourceFile);

            if (!System.IO.File.Exists(sourceFile))
            {
                WriteError(new ErrorRecord(new FileNotFoundException(string.Format("File {0} not found", sourceFile)), "100", ErrorCategory.OpenError, sourceFile));
                return;
            }

            if (outputName != string.Empty)
            {
                if (outputName.StartsWith(@".\"))
                {
                    outputName = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, outputName.Substring(2));
                }
                else
                {
                    outputName = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, outputName);
                }

                outputName = System.IO.Path.GetFullPath(outputName);

                if (System.IO.File.Exists(outputName))
                {
                    if (noClobber)
                    {
                        WriteError(new ErrorRecord(new IOException(string.Format("File {0} already exists", outputName)), "100", ErrorCategory.OpenError, outputName));
                        return;
                    }
                    else
                    {
                        File.Delete(outputName);
                    }
                }
            }
            else
            {
                string destPath   = System.IO.Path.GetDirectoryName(sourceFile);
                string scriptName = System.IO.Path.GetFileNameWithoutExtension(sourceFile);
                outputName = System.IO.Path.Combine(destPath, string.Format("{0}.exe", scriptName));

                if (System.IO.File.Exists(outputName))
                {
                    if (noClobber)
                    {
                        WriteError(new ErrorRecord(new IOException(string.Format("File {0} already exists", outputName)), "100", ErrorCategory.OpenError, outputName));
                        return;
                    }
                    else
                    {
                        File.Delete(outputName);
                    }
                }
            }


            if (iconPath != string.Empty)
            {
                if (iconPath.StartsWith(@".\"))
                {
                    iconPath = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, iconPath.Substring(2));
                }
                else
                {
                    iconPath = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, iconPath);
                }

                iconPath = System.IO.Path.GetFullPath(iconPath);

                if (!System.IO.File.Exists(iconPath))
                {
                    WriteError(new ErrorRecord(new FileNotFoundException(string.Format("File {0} not found", iconPath)), "100", ErrorCategory.OpenError, iconPath));
                    return;
                }
            }
            else
            {
                string tempIcon = sourceFile.ToLower().Replace(".ps1", ".ico");
                if (System.IO.File.Exists(tempIcon))
                {
                    iconPath = tempIcon;
                }
            }

            if (frameworkVersion == string.Empty)
            {
                frameworkVersion = Environment.Version.ToString().Substring(0, 3);
            }


            ApplicationData appData;

            if (makeService)
            {
                appData = new ServiceData();
                ((ServiceData)appData).Description = serviceDesc;
                ((ServiceData)appData).ServiceName = serviceName;
                ((ServiceData)appData).DisplayName = serviceDisplay;
            }
            else
            {
                appData = new ApplicationData();
            }

            appData.DebugBuild   = debug;
            appData.EmbedCore    = embedCore;
            appData.EmbedModules = embedModules;
            appData.Framework    = EnumExtensions.FromString <Framework>(string.Format("Framework{0}", frameworkVersion.Replace(".", "")));
            appData.HideConsole  = hideConsole;
            if (!string.IsNullOrWhiteSpace(iconPath))
            {
                appData.Icon = new Bitmap(iconPath);
            }
            appData.LCID                  = lcid;
            appData.Mode                  = threadMode;
            appData.Platform              = exePlatform;
            appData.PublisherName         = ownerName;
            appData.PublisherOrganization = ownerOrg;
            appData.Version               = new Version(version);
            appData.ApplicationName       = System.IO.Path.GetFileNameWithoutExtension(sourceFile);

            if (signFile)
            {
                appData.SigningInformation                 = new SingingInformation();
                appData.SigningInformation.Certificate     = signCert;
                appData.SigningInformation.TimestampServer = signUrl;
            }

            WriteObject(Compiler.CompileStandard(this, sourceFile, outputName, appData));
        }
Ejemplo n.º 7
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            sourceFile = FixPath(sourceFile);

            if (!System.IO.File.Exists(sourceFile))
            {
                WriteError(new ErrorRecord(new FileNotFoundException(string.Format("File {0} not found", sourceFile)), "100", ErrorCategory.OpenError, sourceFile));
                return;
            }

            if (outputName != string.Empty)
            {
                if (outputName.StartsWith(@".\"))
                {
                    outputName = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, outputName.Substring(2));
                }
                else
                {
                    outputName = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, outputName);
                }

                outputName = System.IO.Path.GetFullPath(outputName);

                if (System.IO.File.Exists(outputName))
                {
                    WriteError(new ErrorRecord(new IOException(string.Format("File {0} already exists", outputName)), "100", ErrorCategory.OpenError, outputName));
                    return;
                }
            }
            else
            {
                string destPath   = System.IO.Path.GetDirectoryName(sourceFile);
                string scriptName = System.IO.Path.GetFileNameWithoutExtension(sourceFile);
                outputName = System.IO.Path.Combine(destPath, string.Format("{0}.exe", scriptName));

                if (System.IO.File.Exists(outputName))
                {
                    WriteError(new ErrorRecord(new IOException(string.Format("File {0} already exists", outputName)), "100", ErrorCategory.OpenError, outputName));
                    return;
                }
            }


            if (iconPath != string.Empty)
            {
                if (iconPath.StartsWith(@".\"))
                {
                    iconPath = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, iconPath.Substring(2));
                }
                else
                {
                    iconPath = System.IO.Path.Combine(this.CurrentProviderLocation("FileSystem").ProviderPath, iconPath);
                }

                iconPath = System.IO.Path.GetFullPath(iconPath);

                if (!System.IO.File.Exists(iconPath))
                {
                    WriteError(new ErrorRecord(new FileNotFoundException(string.Format("File {0} not found", iconPath)), "100", ErrorCategory.OpenError, iconPath));
                    return;
                }
            }
            else
            {
                string tempIcon = sourceFile.ToLower().Replace(".htapp", ".ico");
                if (System.IO.File.Exists(tempIcon))
                {
                    iconPath = tempIcon;
                }
            }

            if (frameworkVersion == string.Empty)
            {
                frameworkVersion = Environment.Version.ToString().Substring(0, 3);
            }


            ApplicationData appData = new ApplicationData();

            appData.DebugBuild            = debug;
            appData.EmbedCore             = embedCore;
            appData.EmbedModules          = embedModules;
            appData.Framework             = EnumExtensions.FromString <Framework>(string.Format("Framework{0}", frameworkVersion.Replace(".", "")));
            appData.HideConsole           = true;
            appData.Icon                  = new Bitmap(iconPath);
            appData.LCID                  = lcid;
            appData.Mode                  = ThreadMode.STA;
            appData.Platform              = exePlatform;
            appData.PublisherName         = ownerName;
            appData.PublisherOrganization = ownerOrg;
            appData.Version               = new Version(version);

            if (signFile)
            {
                appData.SigningInformation                 = new SingingInformation();
                appData.SigningInformation.Certificate     = signCert;
                appData.SigningInformation.TimestampServer = signUrl;
            }

            string replaceProgram = Resources.Templates.Program;

            replaceProgram = replaceProgram.Replace("$$FILENAME$$", Path.GetFileName(sourceFile));

            appData.ReplaceProgram = replaceProgram;
            appData.AdditionalCode.Add(Resources.Templates.ScriptForm);
            appData.AdditionalCode.Add(Resources.Templates.ScriptForm_Designer);
            appData.AdditionalCode.Add(Resources.Templates.ScriptInterface);
            appData.AdditionalCode.Add(Resources.Templates.CrossThread);
            appData.AdditionalCode.Add(Resources.Templates.StringExtension);

            appData.AdditionalFiles.Add(sourceFile);

            foreach (string additionalFile in additionalFiles)
            {
                string additionalFilePath = FixPath(additionalFile);

                if (!System.IO.File.Exists(additionalFilePath))
                {
                    WriteWarning(string.Format("Additional file {0} not found", additionalFilePath));
                }
                else
                {
                    appData.AdditionalFiles.Add(additionalFilePath);
                }
            }

            appData.AdditionalAssemblies.Add("System.Windows.Forms");
            appData.AdditionalAssemblies.Add("System.Drawing");

            WriteObject(Compiler.CompileAdvanced(this, outputName, appData));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Handle the request
        /// </summary>
        /// <param name="context">For testing</param>
        /// <returns></returns>
        public MiddlewareResult Dispatch(IHttpContextWrapper context = null)
        {
            var httpContext = context ?? SystemBootstrapper.GetInstance <IHttpContextWrapper>();

            // execute custom url handlers
            foreach (var handler in CustomUrlHandlers)
            {
                var result = handler.RenderContent(httpContext);
                // check if url maches
                if (result != MiddlewareResult.DoNothing)
                {
                    return(result);
                }
            }

            // get valid process type
            var validType = ProcessRepository.All(type => Filters.All(filter => filter.IsCorrectProcessType(type, httpContext))).FirstOrDefault();

            if (validType.IsNull())
            {
                return(MiddlewareResult.StopExecutionAndInvokeNextMiddleware);
            }

            // create instance
            var process = ProcessFactory.Create <VoidResult>(validType);

            if (process.IsNull())
            {
                return(MiddlewareResult.StopExecutionAndInvokeNextMiddleware);
            }

            // execute factory filters
            foreach (var createEvent in FactoryFilters)
            {
                var result = createEvent.IsValidInstance(process, validType, httpContext);
                if (result != MiddlewareResult.DoNothing)
                {
                    return(result);
                }
            }

            var method = EnumExtensions.FromString <SignalsApiMethod>(httpContext.HttpMethod?.ToUpper());

            // determine the parameter binding method
            var parameterBindingAttribute = validType?
                                            .GetCustomAttributes(typeof(SignalsParameterBindingAttribute), false)
                                            .Cast <SignalsParameterBindingAttribute>()
                                            .FirstOrDefault();

            // resolve default if not provided
            if (parameterBindingAttribute.IsNull())
            {
                DefaultModelBinders.TryGetValue(method, out var modelBinder);
                parameterBindingAttribute = new SignalsParameterBindingAttribute(modelBinder);
            }

            var requestInput = parameterBindingAttribute.Binder.Bind(httpContext);

            // execute process
            var response = new VoidResult();

            // decide if we need to execute
            switch (method)
            {
            case SignalsApiMethod.OPTIONS:
            case SignalsApiMethod.HEAD:
                break;

            default:
                response = ProcessExecutor.Execute(process, requestInput);
                break;
            }

            // post execution events
            foreach (var executeEvent in ResultHandlers)
            {
                var result = executeEvent.HandleAfterExecution(process, validType, response, httpContext);
                if (result != MiddlewareResult.DoNothing)
                {
                    // flag to stop pipe execution
                    return(result);
                }
            }

            // flag to stop pipe execution
            return(MiddlewareResult.StopExecutionAndStopMiddlewarePipe);
        }