Esempio n. 1
0
        /// <summary>
        ///     Create and initialise a zfapi object
        /// </summary>
        private void CreateZfAPIObject()
        {
            // Create new object
            zfAPI = new ZfLib.ZfAPIClass();

            // Set up Zetafax API
            zfAPI.Escape("TRACE", IsAPILogging);
            zfAPI.Escape("APPLICATION", 0x1057);                // don't check for an API licence
            zfAPI.AutoTempDirectory   = true;                   // use \zfax\users\<user> for temp directory
            zfAPI.EnableImpersonation = ZetafaxConfiguration.APIImpersonation;

            if (ZetafaxConfiguration.ZetafaxServer != String.Empty)
            {
                ApplicationLog.WriteInfo("ZfAPI directories (" + ZetafaxConfiguration.ZetafaxServer + ", "
                                         + ZetafaxConfiguration.ZetafaxSystem + ", " + ZetafaxConfiguration.ZetafaxUsers + ", "
                                         + ZetafaxConfiguration.ZetafaxRequest + ")");

                zfAPI.SetZetafaxDirs(ZetafaxConfiguration.ZetafaxServer,
                                     ZetafaxConfiguration.ZetafaxSystem,
                                     ZetafaxConfiguration.ZetafaxUsers,
                                     ZetafaxConfiguration.ZetafaxRequest);
            }
            else
            {
                ApplicationLog.WriteInfo("No Zetafax directories in web.config. Using ZETAFAX.INI");
            }
        }
        /*
         *  Tag activities for the selected date range. All activities are returned.
         *  We usually append a hidden tag (the ones preceded with a colon (:)) so we know which plugin was responsible for them.
         *  Below we filter the list to get only tags from this plugin. You can easily just skip that and process all of them.
         *
         *  In this sample we only get the tags from this plugin, then save them to a local file.
         */
        public static void ExportTags(TagActivity[] allTagActivities, DateRange range)
        {
            var pluginTags = allTagActivities
                             .Where(ta => ta.Groups.Select(g => g.DisplayKey.ToLower()).Contains(ClientPlugin.HiddenTagLabel.ToLower()));

            var rows         = pluginTags.Select(t => t.DisplayName + "\t" + t.StartTime + "\t" + t.EndTime);
            var exportString = rows.Aggregate("", (sum, row) => sum + (sum == "" ? "" : "\n") + row);

            if (!Directory.Exists("c:\\ManicTimeData"))
            {
                Directory.CreateDirectory("c:\\ManicTimeData");
            }

            File.WriteAllText("c:\\ManicTimeData\\sampleExport.txt", exportString);
            ApplicationLog.WriteInfo("Data exported to: c:\\ManicTimeData\\sampleExport.txt");
            MessageBox.Show("Data exported to c:\\ManicTimeData\\sampleExport.txt");
        }
Esempio n. 3
0
 /// <summary>
 /// One of the configuration files or sources changed, check to see if it was ours.
 /// </summary>
 static void ApplicationConfiguration_ConfigurationFileChanged(object sender, ConfigurationFileChangedEventArgs e)
 {
     try
     {
         if ((string.IsNullOrEmpty(DatabaseSettings.SectionInformation.ConfigSource) && (string.Compare(ApplicationConfiguration.AppConfig.FilePath, e.FullPath, true) == 0))
             ||
             string.Compare(DatabaseSettings.SectionInformation.ConfigSource, e.FileName, true) == 0)
         {
             LoadConfigurationSettings(ApplicationConfiguration.AppConfig);
             ApplicationLog.WriteInfo("Database settings were reloaded from " + e.FullPath);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(string.Format("Unable to reload the settings from {0}. ", e.FullPath) + ex.ToString());
     }
 }
Esempio n. 4
0
        /// <summary>
        ///     Tried to find the Zetafax API in the application cache.
        ///     If it cannot find it it logs on to the Zetafax API as the correct user,
        ///     the stores it in the application cache.
        /// </summary>
        protected void InitZfComponents()
        {
            string strName = Context.User.Identity.Name;

            ApplicationLog.WriteInfo("InitZfComponents() for user: " + strName);
            if (ZetafaxConfiguration.EnablePageCache &&
                ZetafaxConfiguration.APICacheExpiresInMins > 0)
            {
                InitZfAPIFromCache(strName);
            }
            else
            {
                // we aren't caching objects - create new Zetafax ones.
                CreateZfAPIObject();
                zfUserSession = zfAPI.Logon(strName, fExclusive_Logon);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Writes the data to the offline file
        /// </summary>
        public void SaveOffline()
        {
            switch (_streamFormat)
            {
            case OfflineFormat.Xml:
                SaveXML();
                break;

            case OfflineFormat.Binary:
                SaveBinary();
                break;

            case OfflineFormat.Encrypt:
                SaveEncrypt();
                break;
            }
            ApplicationLog.WriteInfo("Offline data saved to file '" + OfflineFile + "'");
        }
Esempio n. 6
0
        /// <summary>
        ///     Configures ASP.NET so that the page is returned in the correct language.
        ///     <remarks>
        ///         The algorithm for finding the correct language is as follows:
        ///             - use forcelang override if specified (english on fail)
        ///             - for each request language try language and lang-neutral language
        ///               stop when you find the first one which loads.
        ///     </remarks>
        /// </summary>
        public static ResourceManager ConfigureResources(HttpRequest req)
        {
            ResourceManager rmLocal = new ResourceManager("Zetafax.strings", typeof(PageBase).Assembly);

            if (ZetafaxConfiguration.ForceLangString != String.Empty)
            {
                try
                {
                    // User override of languange
                    CultureInfo cc   = CultureInfo.CreateSpecificCulture(ZetafaxConfiguration.ForceLangString);
                    CultureInfo cuic = new CultureInfo(ZetafaxConfiguration.ForceLangString);
                    Thread.CurrentThread.CurrentCulture   = cc;
                    Thread.CurrentThread.CurrentUICulture = cuic;
                }
                catch (Exception ex)
                {
                    // Somebody probably asked for a language we don't support.
                    // Log it and continue.
                    ApplicationLog.WriteWarning(ApplicationLog.FormatException(ex, "Error forcing CultureInfo"));
                }
            }
            else
            {
                CultureInfo cc   = CultureInfo.CurrentCulture;
                CultureInfo cuic = CultureInfo.CurrentUICulture;
                CultureInfo cen  = new CultureInfo("en");

                // Set the culture and UI culture to the browser's accept language
                string[] arrLanguages = req.UserLanguages;

                // If the browser doesn't specify locale (like outlook)
                if (null == arrLanguages || 0 == arrLanguages.Length)
                {
                    // Use default language if specified
                    if (ZetafaxConfiguration.DefaultLangString != String.Empty)
                    {
                        arrLanguages = new string[] { ZetafaxConfiguration.DefaultLangString };
                    }
                    else
                    {
                        // No defualt - use english
                        arrLanguages = new string[] { "en" };
                    }
                }

                foreach (string strReqLang in arrLanguages)
                {
                    // truncate at ";"
                    int    iSemi = strReqLang.IndexOf(';');
                    string strLang;
                    if (iSemi > 0)
                    {
                        strLang = strReqLang.Substring(0, iSemi);
                    }
                    else
                    {
                        strLang = strReqLang;
                    }

                    try
                    {
                        CultureInfo ccLocal = CultureInfo.CreateSpecificCulture(strLang);
                        if (ccLocal.Equals(cen))
                        {
                            // english culture: break
                            break;
                        }
                        ResourceSet rs = rmLocal.GetResourceSet(ccLocal, true, false);
                        if (rs == null && !ccLocal.IsNeutralCulture)
                        {
                            if (ccLocal.Parent.Equals(cen))
                            {
                                // english culture: break
                                break;
                            }
                            rs = rmLocal.GetResourceSet(ccLocal.Parent, true, false);
                        }

                        if (rs != null)
                        {
                            cc   = ccLocal;
                            cuic = new CultureInfo(strLang);
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        // Somebody probably asked for a language we don't support.
                        // Log it and continue.
                        ApplicationLog.WriteInfo(ApplicationLog.FormatException(ex, "Error setting CultureInfo"));
                    }
                }

                Thread.CurrentThread.CurrentCulture   = cc;
                Thread.CurrentThread.CurrentUICulture = cuic;
            }

            return(rmLocal);
        }
Esempio n. 7
0
        public string FaxReport(string faxNumber)
        {
            string      message = string.Empty;
            bool        success = false;
            eReportType reportType;
            ReportBase  activeReport = this.GetCurrentActiveReport(out reportType);

            if (activeReport != null)
            {
                // Use the override fax number if provided
                if (Configuration.InterFaxOverrideFaxNumber != String.Empty)
                {
                    faxNumber = Configuration.InterFaxOverrideFaxNumber;
                }

                // Strip the faxNumber into a pure telephone number (i.e. no non-numeric characters)
                Regex stripper = new Regex("[^0-9]*");
                faxNumber = stripper.Replace(faxNumber, String.Empty);

                // Create an international number for this UK number
                if (faxNumber.IndexOf("0") == 0)
                {
                    faxNumber = faxNumber.Substring(1);
                    faxNumber = "+44" + faxNumber;
                }

                // Create a memory stream to put the exported PDF into.
                PdfExport    pdfExporter  = new PdfExport();
                MemoryStream outputStream = new MemoryStream();

                // Use the pdf exporter to load the memory stream with the resulting PDF document
                pdfExporter.Export(activeReport.Document, outputStream);

                // Move the position back to the beginning of the stream.
                outputStream.Seek(0, SeekOrigin.Begin);

                // Create a byte array buffer to read the memory stream into.
                byte[] bytes = new byte[outputStream.Length];
                outputStream.Read(bytes, 0, (int)outputStream.Length);

                // Make the fax call (via WS)
                InterFax.InterFax myInterFax = new InterFax.InterFax();

                // Record the audit information
                long transactionId = myInterFax.Sendfax(Configuration.InterFaxUserName, Configuration.InterFaxPassword, faxNumber, bytes, "PDF");

                if (transactionId > 0)
                {
                    // The fax has been sent - record the event
                    Facade.IAudit facAudit = new Facade.Audit();
                    string        userId   = ((Entities.CustomPrincipal)HttpContext.Current.User).UserName;

                    // If faxing Client Delivery & Returns Log, LogId Session variable will be present.
                    if (HttpContext.Current.Session["LogId"] == null)
                    {
                        success = facAudit.FaxSent(reportType, transactionId, faxNumber, userId);
                    }
                    else
                    {
                        success = facAudit.LogFaxSent(transactionId, (int)HttpContext.Current.Session["LogId"], faxNumber, userId);
                    }

                    message = "Your report has been faxed.";
                }
                else
                {
                    message = "Your report has not been faxed. <!--(" + transactionId.ToString() + ")-->";

                    // An error occurred
                    if (Configuration.EventLogEnabled && Configuration.EventLogTraceLevel > 0)
                    {
                        ApplicationLog.WriteInfo("Orchestrator.ReportRunner.FaxReport", "Fax to " + faxNumber.ToString() + " Failed - Error reported as " + transactionId.ToString());
                    }
                }
            }

            return(message);
        }