Exemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                GWUtility.WriteLog("Saving Glasswall Rebuild Api settings changes ...");
                if (string.IsNullOrEmpty(txt_APIUrl.Text.Trim()))
                {
                    lbl_status.Text    = "Glasswall Rebuild Api Url cannot be null. Please enter the URL.";
                    lbl_status.Visible = true;
                    return;
                }
                if (string.IsNullOrEmpty(txt_APIKey.Text.Trim()))
                {
                    lbl_status.Text    = "Glasswall Rebuild Api Key cannot be null. Please enter the key.";
                    lbl_status.Visible = true;
                    return;
                }

                SaveGlasswallRebuildApiSettings(txt_APIUrl.Text.Trim(), txt_APIKey.Text.Trim());

                lbl_status.ForeColor = Color.DarkGreen;
                lbl_status.Text      = "Glasswall Rebuild Api settings saved successfully.";
                lbl_status.Visible   = true;
            }
            catch (Exception ex)
            {
                lbl_status.ForeColor = Color.Red;
                lbl_status.Text      = ex.Message;
                lbl_status.Visible   = true;
            }
        }
 /// <summary>
 /// When document finished upload try process the file, this happens when uploaded from Windows Explorer
 /// </summary>
 public override void ItemUpdated(SPItemEventProperties properties)
 {
     base.ItemUpdated(properties);
     GWUtility.WriteLog($"GW File Updated Event URL:{properties.ListItem.File.Url} Length:{properties.ListItem.File.Length}");
     try
     {
         properties.Web.AllowUnsafeUpdates = true;
         EventFiringEnabled = false;
         var fileItem = properties.ListItem.File;
         if (fileItem != null)
         {
             GWUtility.WriteLog("GW File URL processing ..." + fileItem.Url);
             System.Threading.Thread.Sleep(2000);
             byte[] fileContent = fileItem.OpenBinary();
             System.Threading.Thread.Sleep(2000); // not mandatory but if mp4 file of large size is uploaded it takes seconds to read
             string base64 = Convert.ToBase64String(fileContent);
             byte[] regeneratedFileBytes = new GlasswallRebuildClient().RebuildFile(base64);
             SPItem item = properties.ListItem;
             properties.ListItem["Title"] = "GW_" + fileItem.Name; // just updating the Title to make sure it is processed
             properties.ListItem.SystemUpdate();
             fileItem.SaveBinary(regeneratedFileBytes);
             GWUtility.WriteLog("GW file done :" + properties.ListItem.File.Length);
         }
     }
     catch (Exception ex)
     {
         GWUtility.WriteLog("GW Upload Exception: " + ex.Message + ex.StackTrace);
     }
     finally
     {
         properties.Web.AllowUnsafeUpdates = false;
         EventFiringEnabled = true;
     }
 }
Exemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         if (!Page.IsPostBack)
         {
             GWUtility.WriteLog("Handler JSON Url: " + JSONPATH);
             JObject jsonConfig = JObject.Parse(ReadSettings(JSONPATH));
             foreach (JProperty prop in jsonConfig.Properties())
             {
                 GWUtility.WriteLog($"{prop.Name}- {prop.Value}");
                 if (prop.Name == GWConstants.RebuildApiKeySettingsName)
                 {
                     txt_APIKey.Text = prop.Value.ToString();
                     GWUtility.WriteLog($"GW rebuild api key found: {txt_APIKey.Text.Substring(0,3)}xxxxxxxxx.");
                 }
                 if (prop.Name == GWConstants.RebuildApiUrlSettingsName)
                 {
                     txt_APIUrl.Text = prop.Value.ToString();
                     GWUtility.WriteLog($"GW rebuild api url found: {txt_APIUrl.Text}.");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         lbl_status.Text    = ex.Message;
         lbl_status.Visible = true;
     }
 }
Exemplo n.º 4
0
        private void SaveSettings(string path, string data)
        {
            string sPath = $"{SPUtility.GetCurrentGenericSetupPath(@"TEMPLATE\LAYOUTS")}{GWConstants.SettingsPath}";

            GWUtility.WriteLog($"Saving settings to path:{sPath}");
            File.WriteAllText(sPath, data, Encoding.UTF8);
        }
Exemplo n.º 5
0
        private void PopulateGlasswallRebuildApiSettings()
        {
            SPFarm farmObject = SPFarm.Local;

            if (farmObject.Properties != null && farmObject.Properties.Count > 0)
            {
                if (farmObject.Properties.ContainsKey(GWConstants.PROPS_REBUILD_API_URL))
                {
                    txt_APIUrl.Text = Convert.ToString(farmObject.Properties[GWConstants.PROPS_REBUILD_API_URL]);
                    GWUtility.WriteLog($"Glasswall Rebuild Api Url found: {txt_APIUrl.Text}.");
                }
                if (farmObject.Properties.ContainsKey(GWConstants.PROPS_REBUILD_API_KEY))
                {
                    txt_APIKey.Text = Convert.ToString(farmObject.Properties[GWConstants.PROPS_REBUILD_API_KEY]);
                    string strTrimmedKey = txt_APIKey.Text.Trim().Length > 3 ? txt_APIKey.Text.Trim().Substring(0, 3) : txt_APIKey.Text.Trim();
                    GWUtility.WriteLog($"Glasswall Rebuild Api Key found: {strTrimmedKey}xxxxxxxxx.");
                }
            }
        }
Exemplo n.º 6
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                GWUtility.WriteLog("Saving changes ...");
                if (string.IsNullOrEmpty(txt_APIUrl.Text.Trim()))
                {
                    lbl_status.Text    = "Glasswall rebuild api URL cannot be null. Please enter the URL.";
                    lbl_status.Visible = true;
                    return;
                }
                if (string.IsNullOrEmpty(txt_APIKey.Text.Trim()))
                {
                    lbl_status.Text    = "Glasswall rebuild api key cannot be null. Please enter the key.";
                    lbl_status.Visible = true;
                    return;
                }
                JObject gwSettingsJson = new JObject(
                    new JProperty(GWConstants.RebuildApiKeySettingsName, txt_APIKey.Text),
                    new JProperty(GWConstants.RebuildApiUrlSettingsName, txt_APIUrl.Text)
                    );

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SaveSettings(JSONPATH, gwSettingsJson.ToString());
                }
                                                     );

                lbl_status.ForeColor = Color.DarkGreen;
                lbl_status.Text      = "Application settings successfully saved.";
                lbl_status.Visible   = true;
            }
            catch (Exception ex)
            {
                lbl_status.ForeColor = Color.Red;
                lbl_status.Text      = ex.Message;
                lbl_status.Visible   = true;
            }
        }
 /// <summary>
 /// When document is uploaded to the library try process the file
 /// </summary>
 public override void ItemAdded(SPItemEventProperties properties)
 {
     base.ItemAdded(properties);
     GWUtility.LoadConfiguration(properties.Site.Url);
 }